diff options
| author | Damien George <damien.p.george@gmail.com> | 2020-02-20 14:37:32 +1100 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2020-03-10 01:53:42 +1100 |
| commit | 0ac06a510af8290e2c5e3a1f43c87d232e460b9b (patch) | |
| tree | 7d56089f44df927e7ae19f88b69fe8d0f8420b7d /extmod/modbluetooth.h | |
| parent | 894c550c866211c9f176875d40c15fcf3bf74149 (diff) | |
extmod/modbluetooth: Extract out gatts_db functionality from nimble.
For use by other stacks, if they need it.
Work done in collaboration with Jim Mussared aka @jimmo.
Diffstat (limited to 'extmod/modbluetooth.h')
| -rw-r--r-- | extmod/modbluetooth.h | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/extmod/modbluetooth.h b/extmod/modbluetooth.h index 5e4e2c25a..661130802 100644 --- a/extmod/modbluetooth.h +++ b/extmod/modbluetooth.h @@ -54,10 +54,12 @@ #endif // Common constants. -#ifndef MP_BLUETOOTH_MAX_ATTR_SIZE -#define MP_BLUETOOTH_MAX_ATTR_SIZE (20) +#ifndef MP_BLUETOOTH_DEFAULT_ATTR_LEN +#define MP_BLUETOOTH_DEFAULT_ATTR_LEN (20) #endif +#define MP_BLUETOOTH_CCCB_LEN (2) + // Advertisement packet lengths #define MP_BLUETOOTH_GAP_ADV_MAX_LEN (32) @@ -267,4 +269,34 @@ void mp_bluetooth_gattc_on_data_available_end(void); void mp_bluetooth_gattc_on_write_status(uint16_t conn_handle, uint16_t value_handle, uint16_t status); #endif +// For stacks that don't manage attribute value data (currently all of them), helpers +// to store this in a map, keyed by value handle. + +typedef struct { + // Pointer to heap-allocated data. + uint8_t *data; + // Allocated size of data. + size_t data_alloc; + // Current bytes in use. + size_t data_len; + // Whether new writes append or replace existing data (default false). + bool append; +} mp_bluetooth_gatts_db_entry_t; + +typedef mp_map_t *mp_gatts_db_t; + +STATIC inline void mp_bluetooth_gatts_db_create(mp_gatts_db_t *db) { + *db = m_new(mp_map_t, 1); +} + +STATIC inline void mp_bluetooth_gatts_db_reset(mp_gatts_db_t db) { + mp_map_init(db, 0); +} + +void mp_bluetooth_gatts_db_create_entry(mp_gatts_db_t db, uint16_t handle, size_t len); +mp_bluetooth_gatts_db_entry_t *mp_bluetooth_gatts_db_lookup(mp_gatts_db_t db, uint16_t handle); +int mp_bluetooth_gatts_db_read(mp_gatts_db_t db, uint16_t handle, uint8_t **value, size_t *value_len); +int mp_bluetooth_gatts_db_write(mp_gatts_db_t db, uint16_t handle, const uint8_t *value, size_t value_len); +int mp_bluetooth_gatts_db_resize(mp_gatts_db_t db, uint16_t handle, size_t len, bool append); + #endif // MICROPY_INCLUDED_EXTMOD_MODBLUETOOTH_H |
