ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
GPIO functions

Functions for digitally reading and actuating GPIO pins. More...

Files

file  ruuvi_interface_gpio_interrupt_test.h
 
file  ruuvi_interface_gpio_pwm_test.h
 
file  ruuvi_interface_gpio_test.h
 
file  ruuvi_interface_gpio_interrupt.h
 
file  ruuvi_interface_gpio_pwm.h
 
file  ruuvi_nrf5_sdk15_gpio.c
 
file  ruuvi_nrf5_sdk15_gpio.h
 
file  ruuvi_interface_gpio_pwm.h
 

Data Structures

struct  rd_test_gpio_cfg_t
 structure to configure GPIO test with input and output. These GPIOs must be physically connected on board. More...
 
struct  ri_gpio_evt_t
 Event from GPIO. More...
 

Macros

#define RI_GPIO_INTERRUPT_TEST_TABLE_SIZE   64
 Fixed 64 interrupt table size, adjust this if some device has more than 2 ports with 32 gpios each. More...
 
#define RI_GPIO_PWM_TEST_FREQ_HZ   (100U)
 Frequency of test. More...
 
#define RI_GPIO_PWM_TEST_FREQ_INVALID_MAX_HZ   (17000000U)
 Invalid frequency. More...
 
#define RI_GPIO_PWM_TEST_FREQ_INVALID_MIN_HZ   (1U)
 Invalid frequency. More...
 
#define RI_GPIO_PWM_TEST_DUTY_INVALID_MIN_HZ   (-0.1F)
 Invalid duty cycle. More...
 
#define RI_GPIO_PWM_TEST_DUTY_INVALID_MAX_HZ   (1.1F)
 Invalid duty cycle. More...
 
#define RI_GPIO_PWM_TEST_PERIOD_MS   (1000U / RI_GPIO_PWM_TEST_FREQ_HZ)
 Period of one PWM cycle in ms. More...
 
#define RI_GPIO_PWM_TEST_DC   (0.5F)
 Duty cycle in test. More...
 
#define RI_GPIO_PWM_TEST_TIME_MS   (100U)
 Milliseconds to test. More...
 
#define RI_GPIO_PWM_EXPECT_TRIGS   (RI_GPIO_PWM_TEST_TIME_MS / RI_GPIO_PWM_TEST_PERIOD_MS)
 
#define RI_GPIO_PWM_DRIVER   0
 
#define RI_GPIO_PWM_PLAYBACK_OK   (0)
 
#define RI_GPIO_PWM_PLAYBACK_COUNT   (1)
 
#define RI_GPIO_PWM_DRIVER_PIN_POINT   (0)
 
#define RI_GPIO_PWM_SEQ_DELAY   (0)
 
#define RI_GPIO_PWM_SEQ_REPEATS   (1)
 
#define RI_GPIO_PWM_MAX_FREQ   (16000000.00f)
 
#define RI_GPIO_PWM_MIN_FREQ   (2.00f)
 
#define RI_GPIO_PWM_MAX_DUTY   (1.00f)
 
#define RI_GPIO_PWM_MIN_DUTY   (0.00f)
 
#define RI_GPIO_PWM_CHANNEL_UNUSED   (0)
 
#define RI_GPIO_PWM_MIN_TOP_VALUE   (1U)
 
#define RI_GPIO_PWM_MIN_REST_FOR_TOP   (0.999999f)
 
#define RI_GPIO_PWM_FREQ_COUNT   (8)
 
#define RI_GPIO_PWM_BASE_FREQ_16MHZ   (RI_GPIO_PWM_MAX_FREQ)
 
#define RI_GPIO_PWM_BASE_FREQ_8MHZ   (8000000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_4MHZ   (4000000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_2MHZ   (2000000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_1MHZ   (1000000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_500KHZ   (500000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_250KHZ   (250000.00f)
 
#define RI_GPIO_PWM_BASE_FREQ_125KHZ   (125000.00f)
 

Typedefs

typedef void(* ri_gpio_interrupt_fp_t) (const ri_gpio_evt_t)
 

Enumerations

enum  ri_gpio_slope_t { RI_GPIO_SLOPE_HITOLO , RI_GPIO_SLOPE_LOTOHI , RI_GPIO_SLOPE_TOGGLE , RI_GPIO_SLOPE_UNKNOWN }
 Enable implementation selected by application. More...
 
enum  ri_gpio_base_freq {
  RI_GPIO_PWM_BASE_NUM_FREQ_16MHZ = 0 , RI_GPIO_PWM_BASE_NUM_FREQ_8MHZ = 1 , RI_GPIO_PWM_BASE_NUM_FREQ_4MHZ = 2 , RI_GPIO_PWM_BASE_NUM_FREQ_2MHZ = 3 ,
  RI_GPIO_PWM_BASE_NUM_FREQ_1MHZ = 4 , RI_GPIO_PWM_BASE_NUM_FREQ_500KHZ = 5 , RI_GPIO_PWM_BASE_NUM_FREQ_250KHZ = 6 , RI_GPIO_PWM_BASE_NUM_FREQ_125KHZ = 7
}
 

Functions

rd_status_t ri_gpio_interrupt_test_init (const rd_test_gpio_cfg_t cfg)
 Test GPIO interrupt initialization. More...
 
rd_status_t ri_gpio_interrupt_test_enable (const rd_test_gpio_cfg_t cfg)
 Test enabling interrupt on a pin. More...
 
bool ri_gpio_interrupt_run_integration_test (const rd_test_print_fp printfp, const ri_gpio_id_t input, const ri_gpio_id_t output)
 Run all GPIO interrupt integration tests. More...
 
rd_status_t ri_gpio_pwm_test (const rd_test_gpio_cfg_t cfg)
 Test running PWM on a pin. More...
 
bool ri_gpio_pwm_run_integration_test (const rd_test_print_fp printfp, const ri_gpio_id_t input, const ri_gpio_id_t output)
 Run all GPIO interrupt integration tests. More...
 
rd_status_t ri_gpio_test_init (void)
 Test GPIO module initialization. More...
 
rd_status_t ri_gpio_test_configure (const ri_gpio_id_t input, const ri_gpio_id_t output)
 Test configuring a pin of a port into a mode. More...
 
rd_status_t ri_gpio_test_toggle (const ri_gpio_id_t input, const ri_gpio_id_t output)
 Test toggling the state of a pin of a port. More...
 
bool ri_gpio_run_integration_test (const rd_test_print_fp printfp, const ri_gpio_id_t input, const ri_gpio_id_t output)
 Run all GPIO integration tests. More...
 
rd_status_t ri_gpio_interrupt_init (ri_gpio_interrupt_fp_t *const interrupt_table, const uint16_t max_interrupts)
 Initialize interrupt functionality to GPIO. Takes address of interrupt table as a pointer to avoid tying driver into a specific board with a specific number of GPIO pins and to avoid including boards repository within the driver. The interrupt table must be retained in the RAM. More...
 
rd_status_t ri_gpio_interrupt_uninit (void)
 Uninitialize interrupt functionality of GPIO. More...
 
bool ri_gpio_interrupt_is_init (void)
 Check if interrupt module is initialized. More...
 
rd_status_t ri_gpio_interrupt_enable (const ri_gpio_id_t pin, const ri_gpio_slope_t slope, const ri_gpio_mode_t mode, const ri_gpio_interrupt_fp_t handler)
 Enable interrupt on a pin. More...
 
rd_status_t ri_gpio_interrupt_disable (const ri_gpio_id_t pin)
 Disable interrupt on a pin. More...
 
rd_status_t ri_gpio_pwm_init (void)
 Run any necessary initialization for PWM. More...
 
rd_status_t ri_gpio_pwm_uninit (void)
 Uninitialize PWM. More...
 
rd_status_t ri_gpio_pwm_start (const ri_gpio_id_t pin, const ri_gpio_mode_t mode, float *const frequency, float *const duty_cycle)
 Start PWM on given pin at given frequency and duty cycle. More...
 
rd_status_t ri_gpio_pwm_stop (const ri_gpio_id_t pin)
 Stop PWM on given pin. More...
 
bool ri_gpio_pwm_is_init (void)
 Check if PWM is initialized. More...
 
rd_status_t ri_gpio_init (void)
 Initializes GPIO module. Call this before other GPIO functions. After initialization all GPIO pins shall be in High-Z mode. More...
 
rd_status_t ri_gpio_uninit (void)
 Uninitializes GPIO module. Call this to reset GPIO to High-Z mode. After uninitialization all GPIO pins shall be in High-Z mode. Uninitialization can be called at any time, but behaviour is not defined if some other peripheral (i.e. SPI) is using GPIO pins. More...
 
bool ri_gpio_is_init (void)
 return true if GPIO is init, false otherwise. More...
 
rd_status_t ri_gpio_configure (const ri_gpio_id_t pin, const ri_gpio_mode_t mode)
 Configure a pin of a port into a mode. If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t. More...
 
rd_status_t ri_gpio_toggle (const ri_gpio_id_t pin)
 Toggle the state of a pin of a port. If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t. More...
 
rd_status_t ri_gpio_write (const ri_gpio_id_t pin, const ri_gpio_state_t state)
 Write a pin of a port into given state If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t. More...
 
rd_status_t ri_gpio_read (const ri_gpio_id_t pin, ri_gpio_state_t *const state)
 Read state of a pin of a port into bool high If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t. More...
 

Detailed Description

Functions for digitally reading and actuating GPIO pins.

Enable implementation selected by application.

The GPIO functions do include interrupts, but they do not include PWM, ADC or DAC functions.

Pulse width modulation of GPIO.

Macro Definition Documentation

◆ RI_GPIO_INTERRUPT_TEST_TABLE_SIZE

#define RI_GPIO_INTERRUPT_TEST_TABLE_SIZE   64

Fixed 64 interrupt table size, adjust this if some device has more than 2 ports with 32 gpios each.

Definition at line 21 of file ruuvi_interface_gpio_interrupt_test.h.

◆ RI_GPIO_PWM_BASE_FREQ_125KHZ

#define RI_GPIO_PWM_BASE_FREQ_125KHZ   (125000.00f)

Definition at line 50 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_16MHZ

#define RI_GPIO_PWM_BASE_FREQ_16MHZ   (RI_GPIO_PWM_MAX_FREQ)

Definition at line 43 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_1MHZ

#define RI_GPIO_PWM_BASE_FREQ_1MHZ   (1000000.00f)

Definition at line 47 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_250KHZ

#define RI_GPIO_PWM_BASE_FREQ_250KHZ   (250000.00f)

Definition at line 49 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_2MHZ

#define RI_GPIO_PWM_BASE_FREQ_2MHZ   (2000000.00f)

Definition at line 46 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_4MHZ

#define RI_GPIO_PWM_BASE_FREQ_4MHZ   (4000000.00f)

Definition at line 45 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_500KHZ

#define RI_GPIO_PWM_BASE_FREQ_500KHZ   (500000.00f)

Definition at line 48 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_BASE_FREQ_8MHZ

#define RI_GPIO_PWM_BASE_FREQ_8MHZ   (8000000.00f)

Definition at line 44 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_CHANNEL_UNUSED

#define RI_GPIO_PWM_CHANNEL_UNUSED   (0)

Definition at line 36 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_DRIVER

#define RI_GPIO_PWM_DRIVER   0

Definition at line 23 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_DRIVER_PIN_POINT

#define RI_GPIO_PWM_DRIVER_PIN_POINT   (0)

Definition at line 26 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_EXPECT_TRIGS

#define RI_GPIO_PWM_EXPECT_TRIGS   (RI_GPIO_PWM_TEST_TIME_MS / RI_GPIO_PWM_TEST_PERIOD_MS)

Definition at line 29 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_FREQ_COUNT

#define RI_GPIO_PWM_FREQ_COUNT   (8)

Definition at line 41 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MAX_DUTY

#define RI_GPIO_PWM_MAX_DUTY   (1.00f)

Definition at line 33 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MAX_FREQ

#define RI_GPIO_PWM_MAX_FREQ   (16000000.00f)

Definition at line 30 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MIN_DUTY

#define RI_GPIO_PWM_MIN_DUTY   (0.00f)

Definition at line 34 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MIN_FREQ

#define RI_GPIO_PWM_MIN_FREQ   (2.00f)

Definition at line 31 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MIN_REST_FOR_TOP

#define RI_GPIO_PWM_MIN_REST_FOR_TOP   (0.999999f)

Definition at line 39 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_MIN_TOP_VALUE

#define RI_GPIO_PWM_MIN_TOP_VALUE   (1U)

Definition at line 38 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_PLAYBACK_COUNT

#define RI_GPIO_PWM_PLAYBACK_COUNT   (1)

Definition at line 25 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_PLAYBACK_OK

#define RI_GPIO_PWM_PLAYBACK_OK   (0)

Definition at line 24 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_SEQ_DELAY

#define RI_GPIO_PWM_SEQ_DELAY   (0)

Definition at line 27 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_SEQ_REPEATS

#define RI_GPIO_PWM_SEQ_REPEATS   (1)

Definition at line 28 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ RI_GPIO_PWM_TEST_DC

#define RI_GPIO_PWM_TEST_DC   (0.5F)

Duty cycle in test.

Definition at line 27 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_DUTY_INVALID_MAX_HZ

#define RI_GPIO_PWM_TEST_DUTY_INVALID_MAX_HZ   (1.1F)

Invalid duty cycle.

Definition at line 24 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_DUTY_INVALID_MIN_HZ

#define RI_GPIO_PWM_TEST_DUTY_INVALID_MIN_HZ   (-0.1F)

Invalid duty cycle.

Definition at line 23 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_FREQ_HZ

#define RI_GPIO_PWM_TEST_FREQ_HZ   (100U)

Frequency of test.

Definition at line 20 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_FREQ_INVALID_MAX_HZ

#define RI_GPIO_PWM_TEST_FREQ_INVALID_MAX_HZ   (17000000U)

Invalid frequency.

Definition at line 21 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_FREQ_INVALID_MIN_HZ

#define RI_GPIO_PWM_TEST_FREQ_INVALID_MIN_HZ   (1U)

Invalid frequency.

Definition at line 22 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_PERIOD_MS

#define RI_GPIO_PWM_TEST_PERIOD_MS   (1000U / RI_GPIO_PWM_TEST_FREQ_HZ)

Period of one PWM cycle in ms.

Definition at line 26 of file ruuvi_interface_gpio_pwm_test.h.

◆ RI_GPIO_PWM_TEST_TIME_MS

#define RI_GPIO_PWM_TEST_TIME_MS   (100U)

Milliseconds to test.

Definition at line 28 of file ruuvi_interface_gpio_pwm_test.h.

Typedef Documentation

◆ ri_gpio_interrupt_fp_t

typedef void(* ri_gpio_interrupt_fp_t) (const ri_gpio_evt_t)

Definition at line 45 of file ruuvi_interface_gpio_interrupt.h.

Enumeration Type Documentation

◆ ri_gpio_base_freq

Enumerator
RI_GPIO_PWM_BASE_NUM_FREQ_16MHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_8MHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_4MHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_2MHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_1MHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_500KHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_250KHZ 
RI_GPIO_PWM_BASE_NUM_FREQ_125KHZ 

Definition at line 69 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_slope_t

Enable implementation selected by application.

Enumeration for GPIO slopes

Enumerator
RI_GPIO_SLOPE_HITOLO 

High to low transition

RI_GPIO_SLOPE_LOTOHI 

Low to high transition

RI_GPIO_SLOPE_TOGGLE 

Any transition

RI_GPIO_SLOPE_UNKNOWN 

Error or unknown value.

Definition at line 26 of file ruuvi_interface_gpio_interrupt.h.

Function Documentation

◆ ri_gpio_configure()

rd_status_t ri_gpio_configure ( const ri_gpio_id_t  pin,
const ri_gpio_mode_t  mode 
)

Configure a pin of a port into a mode. If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t.

Parameters
[in]pinPin number.
[in]modeMode to set the pin to. See ri_gpio_mode_t for possible values.
Returns
RD_SUCCESS on success, error code on failure.
RD_ERROR_NOT_SUPPORTED if underlying platform does not support given mode.

Definition at line 77 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_init()

rd_status_t ri_gpio_init ( void  )

Initializes GPIO module. Call this before other GPIO functions. After initialization all GPIO pins shall be in High-Z mode.

Returns
RD_SUCCESS on success
RD_ERROR_INVALID_STATE if GPIO is already initialized

Definition at line 44 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_interrupt_disable()

rd_status_t ri_gpio_interrupt_disable ( const ri_gpio_id_t  pin)

Disable interrupt on a pin.

Pin will be left as RI_GPIO_MODE_HIGH_Z.

Parameters
[in]pinpin to disable as interrupt source.
Return values
RD_SUCCESSon success.

◆ ri_gpio_interrupt_enable()

rd_status_t ri_gpio_interrupt_enable ( const ri_gpio_id_t  pin,
const ri_gpio_slope_t  slope,
const ri_gpio_mode_t  mode,
const ri_gpio_interrupt_fp_t  handler 
)

Enable interrupt on a pin.

Underlying implementation is allowed to use same interrupt channel for all pin interrupts, i.e. simultaneous interrupts might get detected as one and the priority of interrupts is undefined.

  • Return RD_ERROR_INVALID_STATE if GPIO or GPIO_INTERRUPT are not initialized
  • Interrupt function shall be called exactly once when input is configured as low-to-high while input is low and input goes low-to-high, high-to-low.
  • Interrupt function shall not be called after interrupt has been disabled
  • Interrupt function shall be called exactly once when input is configured as high-to-low while input is low and input goes low-to-high, high-to-low.
  • Interrupt function shall be called exactly twice when input is configured as toggle while input is low and input goes low-to-high, high-to-low.
  • Interrupt pin shall be at logic HIGH when interrupt is enabled with a pull-up and the pin is not loaded externally
  • Interrupt pin shall be at logic LOW when interrupt is enabled with a pull-down and the pin is not loaded externally
Parameters
[in]pinpin to use as interrupt source
[in]slopeslope to interrupt on
[in]modeGPIO input mode. Must be (RI_GPIO_)INPUT_PULLUP, INPUT_PULLDOWN or INPUT_NOPULL
[in]handlerfunction pointer which will be called with ri_gpio_evt_t as a parameter on interrupt.
Returns
RD_SUCCESS on success, error code on failure.
Warning
Simultaneous interrupts may be lost. Check the underlying implementation.

◆ ri_gpio_interrupt_init()

rd_status_t ri_gpio_interrupt_init ( ri_gpio_interrupt_fp_t *const  interrupt_table,
const uint16_t  max_interrupts 
)

Initialize interrupt functionality to GPIO. Takes address of interrupt table as a pointer to avoid tying driver into a specific board with a specific number of GPIO pins and to avoid including boards repository within the driver. The interrupt table must be retained in the RAM.

  • Initialization must return RD_ERROR_INVALID_STATE if GPIO is uninitialized
  • Initialization must return RD_SUCCESS on first call.
  • Initialization must return RD_ERROR_INVALID_STATE on second call.
  • Initialization must return RD_SUCCESS after uninitializtion.
  • Initialization must return RD_ERROR_NULL if interrupt handler table is NULL.
Parameters
[in]interrupt_tableArray of function pointers, initialized to all nulls. Size should be the number of GPIO+1, i.e. RUUVI_BOARD_GPIO_NUMBER + 1.
[in]max_interruptsSize of interrupt table.
Returns
RD_SUCCESS on success, error code on failure.

◆ ri_gpio_interrupt_is_init()

bool ri_gpio_interrupt_is_init ( void  )

Check if interrupt module is initialized.

Returns
true if module is initialized, false otherwise

◆ ri_gpio_interrupt_run_integration_test()

bool ri_gpio_interrupt_run_integration_test ( const rd_test_print_fp  printfp,
const ri_gpio_id_t  input,
const ri_gpio_id_t  output 
)

Run all GPIO interrupt integration tests.

Parameters
[in]printfpFunction pointer to which test result strings are sent.
[in]inputPin used to check the state of output pin.
[in]outputPin being toggled.
Returns
false if there are no errors, true otherwise.

◆ ri_gpio_interrupt_test_enable()

rd_status_t ri_gpio_interrupt_test_enable ( const rd_test_gpio_cfg_t  cfg)

Test enabling interrupt on a pin.

Requires basic gpio functionality to work, run gpio tests first. Behaviour is undefined if GPIO is uninitialized while GPIO interrupts are initialized.

  • Return RD_ERROR_INVALID_STATE if GPIO or GPIO_INTERRUPT are not initialized
  • Interrupt function shall be called exactly once when input is configured as low-to-high while input is low and input goes low-to-high, high-to-low.
  • Interrupt function shall not be called after interrupt has been disabled
  • Interrupt function shall be called exactly once when input is configured as high-to-low while input is low and input goes low-to-high, high-to-low.
  • Interrupt function shall be called exactly twice when input is configured as toggle while input is low and input goes low-to-high, high-to-low.
  • Interrupt pin shall be at logic HIGH when interrupt is enabled with a pull-up and the pin is not loaded externally
  • Interrupt pin shall be at logic LOW when interrupt is enabled with a pull-down and the pin is not loaded externally
Parameters
[in]cfgpins to use for testing interrupts
Returns
RD_SUCCESS on success, error code on failure.
Warning
Simultaneous interrupts may be lost. Check the underlying implementation.

◆ ri_gpio_interrupt_test_init()

rd_status_t ri_gpio_interrupt_test_init ( const rd_test_gpio_cfg_t  cfg)

Test GPIO interrupt initialization.

Test GPIO PWM initialization.

  • Initialization must return RD_ERROR_INVALID_STATE if GPIO is uninitialized
  • Initialization must return RD_SUCCESS on first call.
  • Initialization must return RD_ERROR_INVALID_STATE on second call.
  • Initialization must return RD_SUCCESS after uninitializtion.
Parameters
[in]cfgconfiguration of GPIO pins to test.
Returns
RD_SUCCESS on success, error code on failure.

◆ ri_gpio_interrupt_uninit()

rd_status_t ri_gpio_interrupt_uninit ( void  )

Uninitialize interrupt functionality of GPIO.

Returns
RD_SUCCESS on success, error code on failure.

◆ ri_gpio_is_init()

bool ri_gpio_is_init ( void  )

return true if GPIO is init, false otherwise.

Returns
true if GPIO module is init
false if GPIO module is not init

Definition at line 72 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_pwm_init()

rd_status_t ri_gpio_pwm_init ( void  )

Run any necessary initialization for PWM.

After calling this function PWM peripheral may consume power even if no PWM functionality is used.

Return values
RD_SUCCESSInitialization was successful.
RD_ERROR_INVALID_STATEIf PWM was already initialized.
TODOError code on other error.

Definition at line 82 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_pwm_is_init()

bool ri_gpio_pwm_is_init ( void  )

Check if PWM is initialized.

Return values
truePWM is initialized.
falsePWM is not initialized.

Definition at line 112 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_pwm_run_integration_test()

bool ri_gpio_pwm_run_integration_test ( const rd_test_print_fp  printfp,
const ri_gpio_id_t  input,
const ri_gpio_id_t  output 
)

Run all GPIO interrupt integration tests.

Parameters
[in]printfpFunction pointer to which test result strings are sent.
[in]inputPin used to check the state of output pin.
[in]outputPin being toggled.
Returns
false if there are no errors, true otherwise.

◆ ri_gpio_pwm_start()

rd_status_t ri_gpio_pwm_start ( const ri_gpio_id_t  pin,
const ri_gpio_mode_t  mode,
float *const  frequency,
float *const  duty_cycle 
)

Start PWM on given pin at given frequency and duty cycle.

Polarity of PWM is active-high and phase is undefined, implementation is allowed to use centered or edge-triggered PWM.

Parameters
[in]pinPin to start PWM on.
[in]modeOutput mode of GPIO pin, input modes or Hi-Z not supported.
[in,out]frequencyInput: Target frequency, "at least this much". Output: Configured frequency, equal or greater than input.
[in,out]duty_cycleInput: Target duty cycle of PWM, 0.0 ... 1.0. Output: Configured duty cycle, equal or creater than input.
Return values
RD_SUCCESSPWM was started.
RD_ERROR_NULLone or both of pointers was NULL.
RD_ERROR_INVALID_STATEPWM was not initialized.
RD_ERROR_INVALID_PARAMPin, mode, frequency or duty cycle were somehow invalid.

Definition at line 165 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_pwm_stop()

rd_status_t ri_gpio_pwm_stop ( const ri_gpio_id_t  pin)

Stop PWM on given pin.

After calling this function PWM is stopped and given pin is configured as Hi-Z regardless of it's previous state, this can be called on non-PWM pin too.

Parameters
[in]pinPin to stop PWM on.
Return values
RD_SUCCESSIf pin was configured as Hi-Z.
RD_ERROR_INVALID_STATEcurrently not stopped.

Definition at line 238 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_pwm_test()

rd_status_t ri_gpio_pwm_test ( const rd_test_gpio_cfg_t  cfg)

Test running PWM on a pin.

Requires gpio interrupt functionality to work, run gpio interrupt tests first. Behaviour is undefined if GPIO interrupts are uninitialized.

Parameters
[in]cfgpins to use for testing interrupts
Returns
RD_SUCCESS on success, error code on failure.
Warning
Simultaneous interrupts may be lost. Check the underlying implementation.

◆ ri_gpio_pwm_uninit()

rd_status_t ri_gpio_pwm_uninit ( void  )

Uninitialize PWM.

After calling this function PWM peripheral may no longer consume power. GPIO pins may be configured as Hi-Z or they may leave in previous state.

Return values
RD_SUCCESSInitialization was successful.
RD_ERROR_INVALID_STATEIf PWM was already initialized.

Definition at line 95 of file ruuvi_nrf5_sdk15_gpio_pwm.c.

◆ ri_gpio_read()

rd_status_t ri_gpio_read ( const ri_gpio_id_t  pin,
ri_gpio_state_t *const  p_state 
)

Read state of a pin of a port into bool high If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t.

Parameters
[in]pinPin number.
[out]p_statePointer to a ri_gpio_state_t which will be set to the state of the pin.
Returns
RD_SUCCESS on success, error code on failure.
RD_ERROR_NULL if *state is a null pointer.
RD_ERROR_INVALID_ADDRESS if pointer is invalid for any reason (optional).
RD_ERROR_INVALID_STATE if pin was not set as an input (optional).

Definition at line 198 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_run_integration_test()

bool ri_gpio_run_integration_test ( const rd_test_print_fp  printfp,
const ri_gpio_id_t  input,
const ri_gpio_id_t  output 
)

Run all GPIO integration tests.

Parameters
[in]printfpFunction pointer to which test result strings are sent.
[in]inputPin used to check the state of output pin.
[in]outputPin being toggled.
Returns
false if there are no errors, true otherwise.

◆ ri_gpio_test_configure()

rd_status_t ri_gpio_test_configure ( const ri_gpio_id_t  input,
const ri_gpio_id_t  output 
)

Test configuring a pin of a port into a mode.

  • When both pins are in High-Z mode, input is undefined (not tested)
  • When Input is in High-Z mode, and output mode is INPUT_PULLUP, input must read as HIGH
  • When Input is in High-Z mode, and output mode is INPUT_PULLDOWN, input must read as LOW
  • When Input is in INPUT_PULLUP mode, and output is in OUTPUT_LOW mode, input must read as LOW
  • When Input is in INPUT_PULLDOWN mode, and output is in OUTPUT_HIGH mode, input must read as HIGH
Parameters
[in]inputPin used to check the state of output pin
[in]outputPin being configured into various modes.
Returns
RD_SUCCESS if all tests pass, error code on failure

◆ ri_gpio_test_init()

rd_status_t ri_gpio_test_init ( void  )

Test GPIO module initialization.

  • Interface must return RD_SUCCESS after first call.
  • Interface must return RD_ERROR_INVALID_STATE when called while already initialized.
  • Interface must return RD_SUCCESS when called after uninitialization.
    Returns
    RD_SUCCESS if all tests pass, error code on failure

◆ ri_gpio_test_toggle()

rd_status_t ri_gpio_test_toggle ( const ri_gpio_id_t  input,
const ri_gpio_id_t  output 
)

Test toggling the state of a pin of a port.

Input is in High-Z mode. Value read by it must toggle after output pin is toggled.

Parameters
[in]inputPin used to check the state of output pin.
[in]outputPin being toggled.
Returns
RD_SUCCESS if all tests pass, error code on failure

◆ ri_gpio_toggle()

rd_status_t ri_gpio_toggle ( const ri_gpio_id_t  pin)

Toggle the state of a pin of a port. If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t.

Parameters
[in]pinPin number.
Returns
RD_SUCCESS on success, error code on failure.
RD_ERROR_INVALID_STATE if pin was not set as an output (optional).

Definition at line 161 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_uninit()

rd_status_t ri_gpio_uninit ( void  )

Uninitializes GPIO module. Call this to reset GPIO to High-Z mode. After uninitialization all GPIO pins shall be in High-Z mode. Uninitialization can be called at any time, but behaviour is not defined if some other peripheral (i.e. SPI) is using GPIO pins.

Returns
RD_SUCCESS on success
error code from stack on error

Definition at line 52 of file ruuvi_nrf5_sdk15_gpio.c.

◆ ri_gpio_write()

rd_status_t ri_gpio_write ( const ri_gpio_id_t  pin,
const ri_gpio_state_t  state 
)

Write a pin of a port into given state If there are several ports the platform driver must implement a conversion function from port + pin to uint8_t.

Parameters
[in]pinPin number.
[in]stateState to which the pin should be set to. See ri_gpio_state_t for possible values
Returns
RD_SUCCESS on success, error code on failure.
RD_ERROR_INVALID_STATE if pin was not set as an output (optional).

Definition at line 172 of file ruuvi_nrf5_sdk15_gpio.c.