Driver API and module API of the Smart Remote firmware follow distinct patterns.
Most of the drivers are using similar API calls that reflect the following pattern.
ret_code_t drv_xxx_init(drv_xxx_event_handler_t event_handler);
Initializes the given driver and sets the event handler. Input drivers use the handler to pass new data to upper layers. Output drivers use the handler to confirm execution of the requested action. Note that the event handler can be called from interrupt context.
ret_code_t drv_xxx_enable(); ret_code_t drv_xxx_disable();
Controls the peripheral state. When the peripheral is enabled, it can report or transmit data, but requires more power. A disabled peripheral consumes as little power as possible, but is inoperative.
ret_code_t drv_xxx_schedule_read(<pointer to memory buffer>);
Drivers of peripherals that require polling implement this function to start the readout cycle. The memory pointed by the call is used to store data and will be returned back to the caller in the event handler. Since drivers can perform only one operation at a time, no further readouts should be scheduled until the last one has been confirmed by the event handler.
ret_code_t drv_xxx_action();
Some peripherals implement dedicated API calls to perform peripheral-specific operations. Execution of such operations is confirmed by an event handler call. An example of such a peripheral is the drv_ir_sirc driver, which implements a drv_ir_send_symbol() call to send SIRC symbols using infrared.
bool drv_xxx_wakeup_prepare(bool wakeup);
This function prepares the peripheral for deep sleep and subsequent wakeup (if the wakeup parameter is true).
The module API is similar to the driver API and also follows a pattern.
ret_code_t m_xxx_init();
Initializes the given module and the underlying driver.
ret_code_t m_xxx_enable(); ret_code_t m_xxx_disable();
Enables or disables the given module.
bool m_xxx_event_handler(const event_t *p_event);
Interface to the event bus. This function is called for each event in the system.
bool m_xxx_wakeup_prepare(m_pwr_mgmt_shutdown_type_t shutdown_type);
This function prepares the given module and the underlying driver for deep sleep and subsequent wakeup (depending on the shutdown type).