rocketlib function reference
-
struct pwm_pin_config_t
Structure to hold the configuration details for a PWM pin.
- file common.h
Defines
-
ROCKETLIB_VERSION_MAJOR
Rocketlib major release number, shall be design cycle year.
-
ROCKETLIB_VERSION_MINOR
Rocketlib minor release number, shall be the Nth release of the design cycle.
-
w_assert(statement)
Assertion.
Works just like standard C assertion, except use can define custom assertion failure handler(see
w_assert_fail), only active whenW_DEBUGis defined
Enums
-
enum w_status_t
Standard error code.
Values:
-
enumerator W_SUCCESS
Success.
-
enumerator W_FAILURE
Failure, if not one of the more specific case below.
-
enumerator W_INVALID_PARAM
Illegal function call arguments/parameters.
-
enumerator W_IO_ERROR
IO error, for example no SD card was plugged in.
-
enumerator W_IO_TIMEOUT
IO timeout, for example SD card takes too long to respond.
-
enumerator W_MATH_ERROR
Math error, for example divide by zero.
-
enumerator W_OVERFLOW
Buffer overflow, for example trying to write to a full FIFO.
-
enumerator W_SUCCESS
Functions
-
void w_assert_fail(const char *file, int line, const char *statement)
Assertion fail handler.
Assertion fail handler, shall be implemented in the firmware, only used if
W_DEBUGis defined- Parameters:
file – Path to C source file contains assertion failure
line – C source line number of assertion failure
statement – Statement caused assertion failure
-
ROCKETLIB_VERSION_MAJOR
- file crc8.h
Functions
-
uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc)
Compute CRC8.
Computes the CRC8 checksum of input data
- Parameters:
pdata – Input data buffer
nbytes – Buffer size in bytes
crc – CRC8 checksum of previous CRC8 calculation if calculating checksum on multiple discontinuous buffers, otherwise 0
- Returns:
Computed CRC8 checksum
-
uint8_t crc8_checksum(const uint8_t *pdata, size_t nbytes, uint8_t crc)
- file electrical.h
- file i2c.h
PIC18 I2C master driver.
This module provides I2C master functionality for the PIC18F26K83 microcontroller. It supports standard I2C operations including read/write data and register read/write operations for 8-bit and 16-bit registers.
Defines
-
I2C_POLL_TIMEOUT
Configuration constants for I2C interface.
These define the behavior and timing characteristics of the I2C interface Maximum cycles to wait during I2C operations
-
I2C_STRETCH_DELAY
Microseconds to delay during clock stretching.
-
I2C_CLOCK_FREQ
Default I2C clock frequency (100 kHz)
Functions
-
w_status_t i2c_init(uint8_t clkdiv)
Initialize I2C controller with specified clock settings.
This function initializes the I2C module in master mode with the specified clock divider. The clock divider determines the I2C bus frequency:
0 = 100kHz (standard mode)
1 = 50kHz
2 = 25kHz
etc.
- Parameters:
clkdiv – Clock divider (0-7) that determines I2C frequency
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR if initialization fails
-
w_status_t i2c_write_data(uint8_t address, const uint8_t *data, uint8_t len)
Write data to an I2C device.
This function writes a sequence of bytes to the specified I2C device address.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
data – Pointer to the data buffer to write
len – Number of bytes to write
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
w_status_t i2c_read_data(uint8_t address, uint8_t *data, uint8_t len)
Read data from an I2C device.
This function reads a sequence of bytes from the specified I2C device address.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
data – Pointer to the data buffer to store read data
len – Number of bytes to read
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
w_status_t i2c_write_reg8(uint8_t address, uint8_t reg, uint8_t val)
Write an 8-bit value to a register on an I2C device.
This function writes a single 8-bit value to a specific register address on the I2C device.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
reg – Register address to write to
val – 8-bit value to write
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
w_status_t i2c_write_reg16(uint8_t address, uint8_t reg, uint16_t val)
Write a 16-bit value to a register on an I2C device.
This function writes a 16-bit value (MSB first) to a specific register address on the I2C device.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
reg – Register address to write to
val – 16-bit value to write (MSB first)
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
w_status_t i2c_read_reg8(uint8_t address, uint8_t reg, uint8_t *value)
Read an 8-bit value from a register on an I2C device.
This function reads a single 8-bit value from a specific register address on the I2C device.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
reg – Register address to read from
value – Pointer to store the read 8-bit value
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
w_status_t i2c_read_reg16(uint8_t address, uint8_t reg, uint16_t *value)
Read a 16-bit value from a register on an I2C device.
This function reads a 16-bit value (MSB first) from a specific register address on the I2C device.
- Parameters:
address – I2C device address (7-bit, will be shifted left by 1)
reg – Register address to read from
value – Pointer to store the read 16-bit value
- Returns:
w_status_t Returns W_SUCCESS on success, W_IO_ERROR on error, W_IO_TIMEOUT on timeout
-
I2C_POLL_TIMEOUT
- file low_pass_filter.h
Low-pass filter implementation.
This module provides a low-pass filter implementation for smoothing sensor readings and reducing noise in analog signals. The filter uses an exponential moving average algorithm with configurable response time.
Functions
-
static inline double sample_freq(double time_diff_ms)
Calculate the sample frequency based on the time difference in milliseconds.
- Parameters:
time_diff_ms – Time difference between samples in milliseconds
- Returns:
double Sample frequency in Hz
-
static inline double low_pass_alpha(double TR, double time_diff_ms)
Calculate the alpha value for the low-pass filter based on the response time.
The alpha value determines the filter’s responsiveness. A higher alpha value results in faster response but less filtering, while a lower alpha value provides more filtering but slower response.
- Parameters:
TR – Response time constant in milliseconds
time_diff_ms – Time difference between samples in milliseconds
- Returns:
double Alpha value (0.0 to 1.0) for the low-pass filter
-
w_status_t low_pass_filter_init(double *alpha, double response_time)
Initializes the low-pass filter by calculating and storing the alpha value.
This function calculates the alpha value based on the given response time and stores it in the provided pointer. The alpha value is used in subsequent filter updates.
- Parameters:
alpha – Pointer to store the calculated alpha value
response_time – Response time constant in milliseconds (must be > 0)
- Returns:
w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if alpha is NULL or response_time is invalid
-
w_status_t update_low_pass(double alpha, uint16_t new_input_value, double *low_pass_value)
Updates the low-pass filter with a new value and returns the operation status.
This function applies the low-pass filter algorithm to the new input value using the provided alpha value. The filtered result is stored in low_pass_value and updated in-place for the next iteration.
- Parameters:
alpha – Alpha value (0.0 to 1.0) for the low-pass filter
new_input_value – New input value to filter
low_pass_value – Pointer to the current filtered value (updated in-place)
- Returns:
w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if low_pass_value is NULL or alpha is out of valid range (0.0 to 1.0)
-
static inline double sample_freq(double time_diff_ms)
- file pwm.h
PIC18 PWM (CCP) driver.
This module provides PWM functionality using the PIC18 Capture/Compare/PWM (CCP) modules. It supports up to 4 CCP modules (CCP1-CCP4) and uses Timer2 as the timebase for PWM generation.
Defines
-
CONCAT2(a, b)
Macro to concatenate two tokens for register naming.
This macro concatenates two tokens together, used for constructing register names dynamically
-
CONCAT(a, b, c)
Macro to concatenate tokens for register naming.
This macro concatenates three tokens together, used for constructing register names dynamically
-
CCPR_L(module)
Macro to get the CCPR Low register based on module number.
This macro forms the register name for the low byte of the Compare/Capture/PWM register
- Parameters:
module – CCP module number (1-4)
-
CCPR_H(module)
Macro to get the CCPR High register based on module number.
This macro forms the register name for the high byte of the Compare/Capture/PWM register
- Parameters:
module – CCP module number (1-4)
-
CCP_CON(module)
Macro to get the CCPxCON register based on module number.
This macro forms the register name for the control register of the specified CCP module.
- Parameters:
module – CCP module number (1-4)
Functions
-
w_status_t pwm_init(uint8_t ccp_module, pwm_pin_config_t pin_config, uint16_t pwm_period)
Initializes the PWM for a specific CCP module.
This function configures a CCP module for PWM operation. It sets up the pin configuration, enables PWM mode, and configures Timer2 as the timebase. The PWM period is set based on the Timer2 period register (PR2).
- Parameters:
ccp_module – CCP module number (1-4)
pin_config – Pin configuration structure containing TRIS register pointer, PPS register pointer, and pin number
pwm_period – PWM period value (0-255) loaded into PR2 register
- Returns:
w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of range
-
w_status_t pwm_update_duty_cycle(uint8_t ccp_module, uint16_t duty_cycle)
Example usage:
pwm_pin_config_t config; config.tris_reg = &TRISA; // Direct register pointer config.pps_reg = &RA0PPS; // Direct register pointer for PPS config.pin = 0; // Pin number (0-7) pwm_init(1, config, 255); // Initialize PWM on CCP1 with period 255
Updates the duty cycle of the specified CCP module
This function updates the PWM duty cycle for a given CCP module. The duty cycle is a 10-bit value (0-1023) where 0 represents 0% duty cycle and 1023 represents 100% duty cycle.
- Parameters:
ccp_module – CCP module number (1-4)
duty_cycle – Duty cycle value (0-1023) for 10-bit PWM resolution
- Returns:
w_status_t Returns W_SUCCESS on success, W_INVALID_PARAM if module number is out of range or duty cycle exceeds 1023
-
CONCAT2(a, b)
- file timer.h
PIC18 Timer driver provides millis function.
This module provides basic timer functionalities, such as initializing Timer0, handling interrupts, and tracking milliseconds since the timer was started.
Functions
-
void timer0_init(void)
Initializes Timer0 for time tracking. This function must be called before using any other timer-related functionality.
Enables Timer0 interrupt.
Sets the timer to 8-bit mode.
Driven by a 500 kHz clock.
Ensures the timer is synchronized to the system clock.
-
void timer0_handle_interrupt(void)
Function should be called from main ISR when Timer0 interrupt is triggered.
This function should be called from the main Interrupt Service Routine (ISR) whenever the Timer0 interrupt is triggered. It updates the internal time counter.
Warning
This function does not clear the interrupt flag (
PIR3bits.TMR0IF), This is the responsibility of the top level ISR.
-
uint32_t millis(void)
Returns the number of milliseconds since
timer0_init()was called.Returns the number of milliseconds since
timer0_init()was called. This is a safe function that disables interrupts momentarily to return a consistent value.
-
void timer0_init(void)
- dir /home/runner/work/docs/docs/firmware-library
- dir /home/runner/work/docs/docs/firmware-library/rocketlib/rocketlib/include
- dir /home/runner/work/docs/docs/firmware-library/rocketlib
- dir /home/runner/work/docs/docs/firmware-library/rocketlib/rocketlib