51#include "lib/sensors.h"
55#define PRINTF(...) printf(__VA_ARGS__)
60#define ZONIK_INT1_PORT_BASE GPIO_PORT_TO_BASE(ZONIK_INT_PORT)
61#define ZONIK_INT1_PIN_MASK GPIO_PIN_MASK(ZONIK_INT_PIN)
63static uint8_t zonik_buffer[ZONIK_FRAME_SIZE+1];
64static uint16_t zonik_status = ZONIK_DISABLED;
68PROCESS(zonik_stm_process,
"Zonik process process handler");
88 if(
i2c_single_send(ZONIK_ADDR, ZONIK_CMD_READ) != I2C_MASTER_ERR_NONE) {
89 zonik_status = ZONIK_ERROR;
90 PRINTF(
"Zonik: Error in I2C Communication\n");
94 if(zonik_status != ZONIK_ERROR) {
100 I2C_MASTER_ERR_NONE) {
101 zonik_status = ZONIK_ERROR;
102 PRINTF(
"Zonik: Error in I2C Burst Mode Receive");
106 for(i=0; i<ZONIK_FRAME_SIZE; i++) {
107 PRINTF(
" 0x%02x ", zonik_buffer[i]);
111 if(zonik_status != ZONIK_ERROR) {
112 zonik_status = ZONIK_ACTIVE;
134 if(zonik_status == ZONIK_HW_INIT) {
135 return ZONIK_HW_INIT;
138 if(zonik_status != ZONIK_ACTIVE) {
139 return ZONIK_DISABLED;
142 if(type == ZONIK_DBA_LEQ_VALUE) {
143 return ((uint16_t)zonik_buffer[2] << 8) + zonik_buffer[3];
146 if(type == ZONIK_COUNT_VALUE) {
147 return ((uint16_t)zonik_buffer[0] << 8) + zonik_buffer[1];
153configure(
int type,
int value)
155 if(type == ZONIK_ACTIVE) {
156 if(value == ZONIK_VALUE_DEACTIVATE) {
159 zonik_status = ZONIK_DISABLED;
163 i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN,
164 I2C_SCL_NORMAL_BUS_SPEED);
171 zonik_status = ZONIK_HW_INIT;
178SENSORS_SENSOR(zonik, ZONIK_SENSOR, value, configure, status);
Header file with register and macro declarations for the cc2538 GPIO module.
void clock_delay_usec(uint16_t dt)
Delay a given number of microseconds.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE.
#define GPIO_SET_INPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to input.
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE high.
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE low.
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
void i2c_master_enable(void)
Enable master I2C module.
uint8_t i2c_burst_receive(uint8_t slave_addr, uint8_t *data, uint8_t len)
Perform all operations to receive multiple bytes from a slave.
uint8_t i2c_single_send(uint8_t slave_addr, uint8_t data)
Perform all operations to send a byte to a slave.
PROCESS_THREAD(cc2538_rf_process, ev, data)
Implementation of the cc2538 RF driver process.
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
#define PROCESS(name, strname)
Declare a process.
#define PROCESS_EXITHANDLER(handler)
Specify an action when a process exits.
void process_exit(struct process *p)
Cause a process to exit.
#define PROCESS_BEGIN()
Define the beginning of a process.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
#define PROCESS_END()
Define the end of a process.
void process_start(struct process *p, process_data_t data)
Start a process.
Timer library header file.
Header file for the Zolertia Zonik sound sensor.