a serial library to communicate with pebble time's smart strap interface
Dependents: xadow_smartstrap_for_pebble
PebbleSerial.h@0:e4dad9e53f06, 2015-11-04 (annotated)
- Committer:
- KillingJacky
- Date:
- Wed Nov 04 09:58:41 2015 +0000
- Revision:
- 0:e4dad9e53f06
initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KillingJacky | 0:e4dad9e53f06 | 1 | #ifndef __PEBBLE_SERIAL_H__ |
KillingJacky | 0:e4dad9e53f06 | 2 | #define __PEBBLE_SERIAL_H__ |
KillingJacky | 0:e4dad9e53f06 | 3 | |
KillingJacky | 0:e4dad9e53f06 | 4 | #include <stdint.h> |
KillingJacky | 0:e4dad9e53f06 | 5 | #include <stdbool.h> |
KillingJacky | 0:e4dad9e53f06 | 6 | #include <stddef.h> |
KillingJacky | 0:e4dad9e53f06 | 7 | |
KillingJacky | 0:e4dad9e53f06 | 8 | #define PEBBLE_MIN_PAYLOAD (20 + PEBBLE_PAYLOAD_OVERHEAD) |
KillingJacky | 0:e4dad9e53f06 | 9 | #define PEBBLE_PAYLOAD_OVERHEAD 9 |
KillingJacky | 0:e4dad9e53f06 | 10 | |
KillingJacky | 0:e4dad9e53f06 | 11 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
KillingJacky | 0:e4dad9e53f06 | 12 | #define GET_PAYLOAD_BUFFER_SIZE(max_data_length) \ |
KillingJacky | 0:e4dad9e53f06 | 13 | MAX(max_data_length + PEBBLE_PAYLOAD_OVERHEAD, PEBBLE_MIN_PAYLOAD) |
KillingJacky | 0:e4dad9e53f06 | 14 | |
KillingJacky | 0:e4dad9e53f06 | 15 | typedef enum { |
KillingJacky | 0:e4dad9e53f06 | 16 | SmartstrapCmdSetBaudRate, |
KillingJacky | 0:e4dad9e53f06 | 17 | SmartstrapCmdSetTxEnabled, |
KillingJacky | 0:e4dad9e53f06 | 18 | SmartstrapCmdWriteByte, |
KillingJacky | 0:e4dad9e53f06 | 19 | SmartstrapCmdWriteBreak |
KillingJacky | 0:e4dad9e53f06 | 20 | } SmartstrapCmd; |
KillingJacky | 0:e4dad9e53f06 | 21 | |
KillingJacky | 0:e4dad9e53f06 | 22 | typedef enum { |
KillingJacky | 0:e4dad9e53f06 | 23 | PebbleBaud9600, |
KillingJacky | 0:e4dad9e53f06 | 24 | PebbleBaud14400, |
KillingJacky | 0:e4dad9e53f06 | 25 | PebbleBaud19200, |
KillingJacky | 0:e4dad9e53f06 | 26 | PebbleBaud28800, |
KillingJacky | 0:e4dad9e53f06 | 27 | PebbleBaud38400, |
KillingJacky | 0:e4dad9e53f06 | 28 | PebbleBaud57600, |
KillingJacky | 0:e4dad9e53f06 | 29 | PebbleBaud62500, |
KillingJacky | 0:e4dad9e53f06 | 30 | PebbleBaud115200, |
KillingJacky | 0:e4dad9e53f06 | 31 | PebbleBaud125000, |
KillingJacky | 0:e4dad9e53f06 | 32 | PebbleBaud230400, |
KillingJacky | 0:e4dad9e53f06 | 33 | PebbleBaud250000, |
KillingJacky | 0:e4dad9e53f06 | 34 | PebbleBaud460800, |
KillingJacky | 0:e4dad9e53f06 | 35 | |
KillingJacky | 0:e4dad9e53f06 | 36 | PebbleBaudInvalid |
KillingJacky | 0:e4dad9e53f06 | 37 | } PebbleBaud; |
KillingJacky | 0:e4dad9e53f06 | 38 | |
KillingJacky | 0:e4dad9e53f06 | 39 | typedef enum { |
KillingJacky | 0:e4dad9e53f06 | 40 | SmartstrapResultOk = 0, |
KillingJacky | 0:e4dad9e53f06 | 41 | SmartstrapResultNotSupported |
KillingJacky | 0:e4dad9e53f06 | 42 | } SmartstrapResult; |
KillingJacky | 0:e4dad9e53f06 | 43 | |
KillingJacky | 0:e4dad9e53f06 | 44 | typedef enum { |
KillingJacky | 0:e4dad9e53f06 | 45 | SmartstrapRequestTypeRead = 0, |
KillingJacky | 0:e4dad9e53f06 | 46 | SmartstrapRequestTypeWrite = 1, |
KillingJacky | 0:e4dad9e53f06 | 47 | SmartstrapRequestTypeWriteRead = 2 |
KillingJacky | 0:e4dad9e53f06 | 48 | } SmartstrapRequestType; |
KillingJacky | 0:e4dad9e53f06 | 49 | |
KillingJacky | 0:e4dad9e53f06 | 50 | |
KillingJacky | 0:e4dad9e53f06 | 51 | typedef void (*SmartstrapCallback)(SmartstrapCmd cmd, uint32_t arg); |
KillingJacky | 0:e4dad9e53f06 | 52 | |
KillingJacky | 0:e4dad9e53f06 | 53 | void pebble_init(SmartstrapCallback callback, PebbleBaud baud, const uint16_t *services, |
KillingJacky | 0:e4dad9e53f06 | 54 | uint8_t num_services); |
KillingJacky | 0:e4dad9e53f06 | 55 | void pebble_prepare_for_read(uint8_t *buffer, size_t length); |
KillingJacky | 0:e4dad9e53f06 | 56 | bool pebble_handle_byte(uint8_t data, uint16_t *service_id, uint16_t *attribute_id, size_t *length, |
KillingJacky | 0:e4dad9e53f06 | 57 | SmartstrapRequestType *type, uint32_t time_ms); |
KillingJacky | 0:e4dad9e53f06 | 58 | bool pebble_write(bool success, const uint8_t *buffer, uint16_t length); |
KillingJacky | 0:e4dad9e53f06 | 59 | void pebble_notify(uint16_t service_id, uint16_t attribute_id); |
KillingJacky | 0:e4dad9e53f06 | 60 | bool pebble_is_connected(uint32_t time); |
KillingJacky | 0:e4dad9e53f06 | 61 | |
KillingJacky | 0:e4dad9e53f06 | 62 | #endif // __PEBBLE_SERIAL_H__ |