Skip to content

Commit

Permalink
Merge pull request #136 from bigclownlabs/btn
Browse files Browse the repository at this point in the history
Btn
  • Loading branch information
blavka committed Oct 11, 2017
2 parents 6341bd1 + 133ffab commit bcb25bd
Show file tree
Hide file tree
Showing 27 changed files with 853 additions and 380 deletions.
9 changes: 5 additions & 4 deletions bcl/inc/bc_adc.h
Expand Up @@ -98,17 +98,18 @@ bool bc_adc_set_event_handler(bc_adc_channel_t channel, void (*event_handler)(bc

//! @brief Begins reading the ADC channel voltage in asynchronous mode
//! @param[in] channel ADC channel
//! @param[out] result Pointer to destination where ADC conversion will be stored
//! @return true On success
//! @return false On failure

bool bc_adc_async_read(bc_adc_channel_t channel);

//! @brief Get the measurement results
//! @brief Get measurement result
//! @param[in] channel ADC channel
//! @param[out] result Pointer to destination where ADC conversion will be stored
//! @param[out] result Pointer to variable where result will be stored
//! @return true On success
//! @return false On failure

void bc_adc_get_result(bc_adc_channel_t channel, void *result);
bool bc_adc_get_result(bc_adc_channel_t channel, void *result);

//! @brief Get voltage on VDDA pin
//! @param[out] vdda_voltage Pointer to destination where VDDA will be stored
Expand Down
111 changes: 111 additions & 0 deletions bcl/inc/bc_analog_sensor.h
@@ -0,0 +1,111 @@
#ifndef _BC_ANALOG_SENSOR_H
#define _BC_ANALOG_SENSOR_H

#include <bc_adc.h>
#include <bc_scheduler.h>

//! @addtogroup bc_analog_sensor bc_analog_sensor
//! @brief Driver for generic analog sensor
//! @{

//! @brief Callback events

typedef enum
{
//! @brief Error event
BC_ANALOG_SENSOR_EVENT_ERROR = 0,

//! @brief Update event
BC_ANALOG_SENSOR_EVENT_UPDATE = 1

} bc_analog_sensor_event_t;

//! @brief Analog sensor instance

typedef struct bc_analog_sensor_t bc_analog_sensor_t;

//! @brief Analog sensor driver interface

typedef struct
{
//! @brief Callback for initialization
void (*init)(bc_analog_sensor_t *self);

//! @brief Callback for enabling analog sensor
void (*enable)(bc_analog_sensor_t *self);

//! @brief Callback for disabling analog sensor
void (*disable)(bc_analog_sensor_t *self);

//! @brief Callback for getting settling interval
bc_tick_t (*get_settling_interval)(bc_analog_sensor_t *self);

} bc_analog_sensor_driver_t;

//! @cond

typedef enum
{
BC_ANALOG_SENSOR_STATE_ERROR = -1,
BC_ANALOG_SENSOR_STATE_ENABLE = 0,
BC_ANALOG_SENSOR_STATE_MEASURE = 1,
BC_ANALOG_SENSOR_STATE_DISABLE = 2,
BC_ANALOG_SENSOR_STATE_UPDATE = 3

} bc_analog_sensor_state_t;

struct bc_analog_sensor_t
{
bc_adc_channel_t _adc_channel;
bc_adc_format_t _adc_format;
const bc_analog_sensor_driver_t *_driver;
bc_scheduler_task_id_t _task_id_interval;
bc_scheduler_task_id_t _task_id_measure;
void (*_event_handler)(bc_analog_sensor_t *, bc_analog_sensor_event_t, void *);
void *_event_param;
bool _measurement_active;
bc_tick_t _update_interval;
bc_analog_sensor_state_t _state;
};

//! @endcond

//! @brief Initialize generic analog sensor
//! @param[in] self Instance
//! @param[in] adc_channel ADC channel
//! @param[in] adc_format ADC result format
//! @param[in] driver Optional driver interface (can be NULL)

void bc_analog_sensor_init(bc_analog_sensor_t *self, bc_adc_channel_t adc_channel, bc_adc_format_t adc_format, const bc_analog_sensor_driver_t *driver);

//! @brief Set callback function
//! @param[in] self Instance
//! @param[in] event_handler Function address
//! @param[in] event_param Optional event parameter (can be NULL)

void bc_analog_sensor_set_event_handler(bc_analog_sensor_t *self, void (*event_handler)(bc_analog_sensor_t *, bc_analog_sensor_event_t, void *), void *event_param);

//! @brief Set measurement interval
//! @param[in] self Instance
//! @param[in] interval Measurement interval

void bc_analog_sensor_set_update_interval(bc_analog_sensor_t *self, bc_tick_t interval);

//! @brief Start measurement manually
//! @param[in] self Instance
//! @return true On success
//! @return false When other measurement is in progress

bool bc_analog_sensor_measure(bc_analog_sensor_t *self);

//! @brief Get measurement result
//! @param[in] self Instance
//! @param[out] result Pointer to variable where result will be stored
//! @return true When value is valid
//! @return false When value is invalid

bool bc_analog_sensor_get_result(bc_analog_sensor_t *self, void *result);

//! @}

#endif // _BC_ANALOG_SENSOR_H
29 changes: 18 additions & 11 deletions bcl/inc/bc_button.h
Expand Up @@ -30,26 +30,33 @@ typedef enum

typedef struct bc_button_t bc_button_t;

//! @brief Button driver interface

typedef struct
{
//! @brief Callback for initialization
void (*init)(bc_button_t *self);

//! @brief Callback for reading input state
int (*get_input)(bc_button_t *self);

} bc_button_driver_t;

//! @cond

typedef union
{
bc_gpio_channel_t gpio_channel;
int virtual_channel;
} bc_button_channel_t;

typedef struct
{
void (*init)(bc_button_t *self);
int (*get_input)(bc_button_t *self);
} bc_button_driver_t;
} bc_button_channel_t;

struct bc_button_t
{
bc_button_channel_t _channel;
const bc_button_driver_t *_driver;
bc_gpio_pull_t _gpio_pull;
bool _idle_state;
int _idle_state;
void (*_event_handler)(bc_button_t *, bc_button_event_t, void *);
void *_event_param;
bc_tick_t _scan_interval;
Expand All @@ -59,7 +66,7 @@ struct bc_button_t
bc_tick_t _tick_debounce;
bc_tick_t _tick_click_timeout;
bc_tick_t _tick_hold_threshold;
bool _state;
int _state;
bool _hold_signalized;
};

Expand All @@ -71,15 +78,15 @@ struct bc_button_t
//! @param[in] gpio_pull GPIO pull-up/pull-down setting
//! @param[in] idle_state GPIO pin idle state (when button is not pressed)

void bc_button_init(bc_button_t *self, bc_gpio_channel_t gpio_channel, bc_gpio_pull_t gpio_pull, bool idle_state);
void bc_button_init(bc_button_t *self, bc_gpio_channel_t gpio_channel, bc_gpio_pull_t gpio_pull, int idle_state);

//! @brief Initialize virtual button
//! @param[in] self Instance
//! @param[in] channel Virtual channel button is connected to
//! @param[in] driver Virtual channel button driver
//! @param[in] idle_state Virtual pin idle state (when LED is supposed to be off)
//! @param[in] idle_state Virtual pin idle state (when button is not pressed)

void bc_button_init_virtual(bc_button_t *self, int channel, const bc_button_driver_t *driver, bool idle_state);
void bc_button_init_virtual(bc_button_t *self, int channel, const bc_button_driver_t *driver, int idle_state);

//! @brief Set callback function
//! @param[in] self Instance
Expand Down
26 changes: 16 additions & 10 deletions bcl/inc/bc_co2_sensor.h
Expand Up @@ -46,7 +46,8 @@ typedef enum

//! @brief CO2 Sensor driver

typedef struct {
typedef struct
{
bool (*init)(void);
bool (*charge)(bool state);
bool (*enable)(bool state);
Expand All @@ -57,7 +58,7 @@ typedef struct {

} bc_co2_sensor_driver_t;

//! @brief CO2 Sensor state
//! @cond

typedef enum
{
Expand All @@ -72,8 +73,6 @@ typedef enum

} bc_co2_sensor_state_t;

//! @brief CO2 Sensor instance

typedef struct
{
const bc_co2_sensor_driver_t *_driver;
Expand All @@ -98,36 +97,43 @@ typedef struct

} bc_co2_sensor_t;

//! @brief Initialize BigClown CO2 Module
//! @endcond

//! @brief Initialize BigClown CO2 Sensor

void bc_co2_sensor_init(bc_co2_sensor_t *self, const bc_co2_sensor_driver_t *driver);

//! @brief Set callback function
//! @param[in] self Instance
//! @param[in] event_handler Function address
//! @param[in] event_param Optional event parameter (can be NULL)

void bc_co2_sensor_set_event_handler(bc_co2_sensor_t *self, void (*event_handler)(bc_co2_sensor_event_t, void *), void *event_param);

//! @brief Set measurement interval
//! @param[in] self Instance
//! @param[in] interval Measurement interval

void bc_co2_sensor_set_update_interval(bc_co2_sensor_t *self, bc_tick_t interval);

//! @brief Start measurement manually
//! @param[in] self Instance
//! @return true On success
//! @return False When other measurement is in progress

bool bc_co2_sensor_measure(bc_co2_sensor_t *self);

//! @brief Get co2 concentration
//! @param[out] concentration in ppm
//! @brief Get CO2 concentration in ppm (parts per million)
//! @param[in] self Instance
//! @param[out] ppm Pointer to variable where result will be stored
//! @return true On success
//! @return false On failure

bool bc_co2_sensor_get_concentration(bc_co2_sensor_t *self, float *concentration);
bool bc_co2_sensor_get_concentration_ppm(bc_co2_sensor_t *self, float *ppm);

//! @brief Set calibration request
//! @param[in] calibration type
//! @brief Request sensor calibration
//! @param[in] self Instance
//! @param[in] calibration Calibration type

void bc_co2_sensor_calibration(bc_co2_sensor_t *self, bc_co2_sensor_calibration_t calibration);

Expand Down
14 changes: 5 additions & 9 deletions bcl/inc/bc_module_co2.h
Expand Up @@ -4,10 +4,6 @@
#include <bc_tick.h>
#include <bc_co2_sensor.h>


#define BC_MODULE_CO2_I2C_GPIO_EXPANDER_ADDRESS 0x38
#define BC_MODULE_CO2_I2C_UART_ADDRESS 0x4D

//! @addtogroup bc_module_co2 bc_module_co2
//! @brief Driver for BigClown CO2 Module
//! @{
Expand Down Expand Up @@ -45,15 +41,15 @@ void bc_module_co2_set_update_interval(bc_tick_t interval);

bool bc_module_co2_measure(void);

//! @brief Get co2 concentration
//! @param[out] concentration in ppm
//! @brief Get CO2 concentration in ppm (parts per million)
//! @param[out] ppm Pointer to variable where result will be stored
//! @return true On success
//! @return false On failure

bool bc_module_co2_get_concentration(float *concentration);
bool bc_module_co2_get_concentration_ppm(float *ppm);

//! @brief Set calibration request
//! @param[in] calibration type
//! @brief Request sensor calibration
//! @param[in] calibration Calibration type

void bc_module_co2_calibration(bc_co2_sensor_calibration_t calibration);

Expand Down
13 changes: 12 additions & 1 deletion bcl/inc/bc_scheduler.h
Expand Up @@ -73,6 +73,12 @@ void bc_scheduler_plan_absolute(bc_scheduler_task_id_t task_id, bc_tick_t tick);

void bc_scheduler_plan_relative(bc_scheduler_task_id_t task_id, bc_tick_t tick);

//! @brief Schedule specified task to tick relative from now
//! @param[in] task_id Task ID to be scheduled
//! @param[in] tick Tick at which the task will be run as a relative value from now

void bc_scheduler_plan_from_now(bc_scheduler_task_id_t task_id, bc_tick_t tick);

//! @brief Schedule current task for immediate execution

void bc_scheduler_plan_current_now(void);
Expand All @@ -87,6 +93,11 @@ void bc_scheduler_plan_current_absolute(bc_tick_t tick);

void bc_scheduler_plan_current_relative(bc_tick_t tick);

//! @brief Schedule current task to tick relative from now
//! @param[in] tick Tick at which the task will be run as a relative value from now

void bc_scheduler_plan_current_from_now(bc_tick_t tick);

//! @}

#endif
#endif // _BC_SCHEDULER_H
2 changes: 2 additions & 0 deletions bcl/inc/bcl.h
Expand Up @@ -20,6 +20,7 @@
#include <bc_led.h>
#include <bc_rtc.h>
#include <bc_uart.h>
#include <bc_spi.h>

// Chip drivers

Expand Down Expand Up @@ -51,6 +52,7 @@

// Other

#include <bc_analog_sensor.h>
#include <bc_data_stream.h>
#include <bc_flood_detector.h>
#include <bc_pulse_counter.h>
Expand Down

0 comments on commit bcb25bd

Please sign in to comment.