Skip to content

Commit 654c0b9

Browse files
committed
Add complete doxygen documentation for pwm.h and pwm.c
1 parent 8caf269 commit 654c0b9

File tree

2 files changed

+65
-11
lines changed

2 files changed

+65
-11
lines changed

include/pwm.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,51 @@ typedef struct {
6262
/**
6363
* @brief Macro to get the CCPxCON register based on module number
6464
*
65-
* This macro forms the register name for the control register of the specified CCP module
65+
* This macro forms the register name for the control register of the specified CCP module.
6666
*
6767
* @param module CCP module number (1-4)
6868
*/
6969
#define CCP_CON(module) CONCAT(CCP, module, CON)
7070

71-
// Function prototypes
72-
w_status_t pwm_init(uint8_t ccp_module, pwm_pin_config_t pin_config,
73-
uint16_t pwm_period); // Initializes the PWM for a specific CCP module
71+
/**
72+
* @brief Initializes the PWM for a specific CCP module
73+
*
74+
* This function configures a CCP module for PWM operation. It sets up the pin configuration,
75+
* enables PWM mode, and configures Timer2 as the timebase. The PWM period is set based on
76+
* the Timer2 period register (PR2).
77+
*
78+
* @param ccp_module CCP module number (1-4)
79+
* @param pin_config Pin configuration structure containing TRIS register pointer, PPS register
80+
* pointer, and pin number
81+
* @param pwm_period PWM period value (0-255) loaded into PR2 register
82+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of range
83+
*/
84+
w_status_t pwm_init(uint8_t ccp_module, pwm_pin_config_t pin_config, uint16_t pwm_period);
7485

7586
/**
76-
* Example usage:
87+
* @brief Example usage:
7788
*
89+
* @code
7890
* pwm_pin_config_t config;
7991
* config.tris_reg = &TRISA; // Direct register pointer
8092
* config.pps_reg = &RA0PPS; // Direct register pointer for PPS
8193
* config.pin = 0; // Pin number (0-7)
8294
*
8395
* pwm_init(1, config, 255); // Initialize PWM on CCP1 with period 255
96+
* @endcode
8497
*/
8598

86-
w_status_t
87-
pwm_update_duty_cycle(uint8_t ccp_module,
88-
uint16_t duty_cycle); // Updates the duty cycle of the specified CCP module
99+
/**
100+
* @brief Updates the duty cycle of the specified CCP module
101+
*
102+
* This function updates the PWM duty cycle for a given CCP module. The duty cycle is a 10-bit
103+
* value (0-1023) where 0 represents 0% duty cycle and 1023 represents 100% duty cycle.
104+
*
105+
* @param ccp_module CCP module number (1-4)
106+
* @param duty_cycle Duty cycle value (0-1023) for 10-bit PWM resolution
107+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of
108+
* range or duty cycle exceeds 1023
109+
*/
110+
w_status_t pwm_update_duty_cycle(uint8_t ccp_module, uint16_t duty_cycle);
89111

90112
#endif /* ROCKETLIB_PWM_H */

pic18f26k83/pwm.c

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
#include "pwm.h"
22
#include <xc.h>
33

4-
// Helper function to configure PPS registers using direct register access
4+
/**
5+
* @brief Helper function to configure PPS registers using direct register access
6+
*
7+
* This function configures the Peripheral Pin Select (PPS) registers to map a CCP module
8+
* to a specific pin. It sets the pin as an output and assigns the CCP module to the PPS register.
9+
*
10+
* @param ccp_module CCP module number (1-4)
11+
* @param pin_config Pin configuration structure containing TRIS register pointer, PPS register
12+
* pointer, and pin number
13+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of range
14+
*/
515
static w_status_t configure_pps(uint8_t ccp_module, pwm_pin_config_t pin_config) {
616
// Ensure the CCP module number is within valid range (1-4)
717
if (ccp_module < 1 || ccp_module > 4) {
@@ -17,7 +27,19 @@ static w_status_t configure_pps(uint8_t ccp_module, pwm_pin_config_t pin_config)
1727
return W_SUCCESS; // Return success status after configuring PPS
1828
}
1929

20-
// Initialize PWM for a specific CCP module
30+
/**
31+
* @brief Initializes the PWM for a specific CCP module
32+
*
33+
* This function configures a CCP module for PWM operation. It sets up the pin configuration,
34+
* enables PWM mode, and configures Timer2 as the timebase. The PWM period is set based on
35+
* the Timer2 period register (PR2).
36+
*
37+
* @param ccp_module CCP module number (1-4)
38+
* @param pin_config Pin configuration structure containing TRIS register pointer, PPS register
39+
* pointer, and pin number
40+
* @param pwm_period PWM period value (0-255) loaded into PR2 register
41+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of range
42+
*/
2143
w_status_t pwm_init(uint8_t ccp_module, pwm_pin_config_t pin_config, uint16_t pwm_period) {
2244
// Configure PPS registers to map CCP module to the selected pin
2345
w_status_t status = configure_pps(ccp_module, pin_config);
@@ -60,7 +82,17 @@ w_status_t pwm_init(uint8_t ccp_module, pwm_pin_config_t pin_config, uint16_t pw
6082
return W_SUCCESS; // Return success status after PWM initialization
6183
}
6284

63-
// Update the duty cycle of a specific CCP module
85+
/**
86+
* @brief Updates the duty cycle of the specified CCP module
87+
*
88+
* This function updates the PWM duty cycle for a given CCP module. The duty cycle is a 10-bit
89+
* value (0-1023) where 0 represents 0% duty cycle and 1023 represents 100% duty cycle.
90+
*
91+
* @param ccp_module CCP module number (1-4)
92+
* @param duty_cycle Duty cycle value (0-1023) for 10-bit PWM resolution
93+
* @return w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of
94+
* range or duty cycle exceeds 1023
95+
*/
6496
w_status_t pwm_update_duty_cycle(uint8_t ccp_module, uint16_t duty_cycle) {
6597
// Validate CCP module and duty cycle range
6698
if (ccp_module < 1 || ccp_module > 4 || duty_cycle > 1023) {

0 commit comments

Comments
 (0)