Firmware SDK
twr_atsha204.h
1 #ifndef _TWR_ATSHA204_H
2 #define _TWR_ATSHA204_H
3 
4 #include <twr_common.h>
5 #include <twr_i2c.h>
6 #include <twr_scheduler.h>
7 
8 #define TWR_ATSHA204_RX_BUFFER_SIZE 32
9 
13 
14 typedef enum
15 {
18 
21 
24 
26 
28 
29 typedef struct twr_atsha204_t twr_atsha204_t;
30 
32 
33 typedef enum
34 {
35  TWR_ATSHA204_STATE_READY = 0,
36  TWR_ATSHA204_STATE_READ_SERIAL_NUMBER = 1,
37  TWR_ATSHA204_STATE_READ_SERIAL_NUMBER2 = 2,
38  TWR_ATSHA204_STATE_SERIAL_NUMBER = 3
39 
40 } twr_atsha204_state_t;
41 
42 struct twr_atsha204_t
43 {
44  twr_i2c_channel_t _i2c_channel;
45  uint8_t _i2c_address;
46  void (*_event_handler)(twr_atsha204_t *, twr_atsha204_event_t, void *);
47  void *_event_param;
48  twr_scheduler_task_id_t _task_id;
49  twr_atsha204_state_t _state;
50  bool _ready;
51  uint8_t _rx_buffer[TWR_ATSHA204_RX_BUFFER_SIZE];
52 
53 };
54 
56 
61 
62 void twr_atsha204_init(twr_atsha204_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address);
63 
68 
69 void twr_atsha204_set_event_handler(twr_atsha204_t *self, void (*event_handler)(twr_atsha204_t *, twr_atsha204_event_t, void *), void *event_param);
70 
75 
77 
82 
84 
91 
92 bool twr_atsha204_get_serial_number(twr_atsha204_t *self, void *destination, size_t size);
93 
95 
96 #endif // _TWR_ATSHA204_H
97 
twr_atsha204_event_t
Definition: twr_atsha204.h:15
bool twr_atsha204_get_serial_number(twr_atsha204_t *self, void *destination, size_t size)
Get serial number.
Definition: twr_atsha204.c:59
bool twr_atsha204_is_ready(twr_atsha204_t *self)
Check if is ready for commands.
Definition: twr_atsha204.c:35
struct twr_atsha204_t twr_atsha204_t
ATSHA204 instance.
Definition: twr_atsha204.h:29
void twr_atsha204_init(twr_atsha204_t *self, twr_i2c_channel_t i2c_channel, uint8_t i2c_address)
Initialize ATSHA204 driver.
Definition: twr_atsha204.c:15
bool twr_atsha204_read_serial_number(twr_atsha204_t *self)
Reqeust for serial number.
Definition: twr_atsha204.c:40
void twr_atsha204_set_event_handler(twr_atsha204_t *self, void(*event_handler)(twr_atsha204_t *, twr_atsha204_event_t, void *), void *event_param)
Set callback function.
Definition: twr_atsha204.c:29
@ TWR_ATSHA204_EVENT_SERIAL_NUMBER
Event serial number is available.
Definition: twr_atsha204.h:23
@ TWR_ATSHA204_EVENT_ERROR
Error event.
Definition: twr_atsha204.h:17
@ TWR_ATSHA204_EVENT_REVISION_NUMBER
Event revision number is available.
Definition: twr_atsha204.h:20
twr_i2c_channel_t
I2C channels.
Definition: twr_i2c.h:16
size_t twr_scheduler_task_id_t
Task ID assigned by scheduler.
Definition: twr_scheduler.h:22