Dawn Framework 1.0
Universal data acquisition framework for embedded systems
prph_aios.hxx
1// dawn/include/dawn/proto/nimble/prph_aios.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <map>
9
10#include "dawn/porting/config.hxx"
11#include "dawn/proto/nimble/iprph.hxx"
12#include "host/ble_gatt.h"
13
14namespace dawn
15{
16// Forward reference
17
18class CProtoNimblePrph;
19
27{
28public:
29 constexpr static uint8_t AIOS_CFG0_SIZE_SHIFT = 0;
30 constexpr static uint8_t AIOS_CFG0_SIZE_MASK = 0b1111;
31 constexpr static uint8_t AIOS_CFG1_AGGREGATE_SHIFT = 0;
32 constexpr static uint8_t AIOS_CFG1_AGGREGATE_MASK = 0b1;
33 constexpr static uint8_t AIOS_OBJCFG_TYPE_SHIFT = 0;
34 constexpr static uint8_t AIOS_OBJCFG_TYPE_MASK = 0b11;
35 constexpr static uint8_t AIOS_EXTCFG_KIND_SHIFT = 0;
36 constexpr static uint8_t AIOS_EXTCFG_KIND_MASK = 0xff;
37 constexpr static uint8_t AIOS_EXTCFG_SIZE_SHIFT = 8;
38 constexpr static uint8_t AIOS_EXTCFG_SIZE_MASK = 0xff;
39 constexpr static uint8_t AIOS_DESC_USER_DESCRIPTION = 1 << 0;
40 constexpr static uint8_t AIOS_DESC_NUMBER_OF_DIGITALS = 1 << 1;
41 constexpr static uint8_t AIOS_DESC_VALUE_TRIGGER_SETTING = 1 << 2;
42 constexpr static uint8_t AIOS_DESC_TIME_TRIGGER_SETTING = 1 << 3;
43 constexpr static uint8_t AIOS_DESC_PRESENTATION_FORMAT = 1 << 4;
44 constexpr static uint8_t AIOS_DESC_EXTENDED_PROPERTIES = 1 << 5;
45 constexpr static uint8_t AIOS_USER_DESCRIPTION_MAX = 16;
46 constexpr static uint8_t AIOS_RAW_DESCRIPTOR_MAX = 16;
47 constexpr static uint8_t AIOS_PRESENTATION_FORMAT_SIZE = 7;
48 constexpr static uint8_t AIOS_EXTENDED_PROPERTIES_SIZE = 2;
49
50 constexpr static uint16_t UUID16_EXTENDED_PROPERTIES = 0x2900;
51 constexpr static uint16_t UUID16_PRESENTATION_FORMAT = 0x2904;
52 constexpr static uint16_t UUID16_CHR_USER_DESCRIPTION = 0x2901;
53 constexpr static uint16_t UUID16_NUMBER_OF_DIGITALS = 0x2909;
54 constexpr static uint16_t UUID16_VALUE_TRIGGER_SETTING = 0x290a;
55 constexpr static uint16_t UUID16_TIME_TRIGGER_SETTING = 0x290e;
56
57 enum
58 {
61 };
62
63 enum
64 {
71 };
72
73 struct
74 {
75 uint32_t cfg;
77 uint32_t extCount;
78 } typedef SProtoNimblePrphIOBindAiosObjid;
79
80 struct
81 {
82 uint32_t cfg0;
83 uint32_t cfg1;
84 uint32_t cfg2;
85
86 uint32_t data[];
87 } typedef SProtoNimblePrphIOBindAios;
88
89 CProtoNimblePrphAios(const SObjectCfg::SObjectCfgItem *item, IProtoNimblePrphCb *cb_);
90
91 ~CProtoNimblePrphAios() override;
92
93 int init() override;
94 int deinit() override;
95 int start() override;
96 int stop() override;
97
98 static uint32_t cfgIdIOBindAiosCfgObj(uint8_t type)
99 {
100 return ((type & AIOS_OBJCFG_TYPE_MASK) << AIOS_OBJCFG_TYPE_SHIFT);
101 }
102
103 static uint8_t cfgIdIOBindAiosCfgObjTypeGet(uint32_t val)
104 {
105 return (val >> AIOS_OBJCFG_TYPE_SHIFT) & AIOS_OBJCFG_TYPE_MASK;
106 }
107
108 static uint32_t cfgIdIOBindAiosExt(uint8_t kind, uint8_t size)
109 {
110 return ((kind & AIOS_EXTCFG_KIND_MASK) << AIOS_EXTCFG_KIND_SHIFT) |
111 ((size & AIOS_EXTCFG_SIZE_MASK) << AIOS_EXTCFG_SIZE_SHIFT);
112 }
113
114 static uint8_t cfgIdIOBindAiosExtKindGet(uint32_t val)
115 {
116 return (val >> AIOS_EXTCFG_KIND_SHIFT) & AIOS_EXTCFG_KIND_MASK;
117 }
118
119 static uint8_t cfgIdIOBindAiosExtSizeGet(uint32_t val)
120 {
121 return (val >> AIOS_EXTCFG_SIZE_SHIFT) & AIOS_EXTCFG_SIZE_MASK;
122 }
123
124 static uint32_t cfgIdIOBindAiosCfg0(uint8_t size)
125 {
126 return ((size & AIOS_CFG0_SIZE_MASK) << AIOS_CFG0_SIZE_SHIFT);
127 }
128
129 static uint8_t cfgIdIOBindAiosCfg0SizeGet(uint32_t val)
130 {
131 return (val >> AIOS_CFG0_SIZE_SHIFT) & AIOS_CFG0_SIZE_MASK;
132 }
133
134 static uint32_t cfgIdIOBindAiosCfg1(uint8_t aggregate)
135 {
136 return ((aggregate & AIOS_CFG1_AGGREGATE_MASK) << AIOS_CFG1_AGGREGATE_SHIFT);
137 }
138
139 static bool cfgIdIOBindAiosCfg1AggregateGet(uint32_t val)
140 {
141 return ((val >> AIOS_CFG1_AGGREGATE_SHIFT) & AIOS_CFG1_AGGREGATE_MASK) != 0;
142 }
143
144 static uint32_t cfgIdIOBindAiosCfg2(uint8_t res)
145 {
146 return 0;
147 }
148
149private:
150 int id;
151 size_t noChar;
152 bool aggregateEnabled;
153 bool created;
154 struct ble_gatt_svc_def svc;
155 std::map<const SObjectId::ObjectId, uint8_t> ioTypeMap;
156 std::map<const SObjectId::ObjectId, SPrphNotiferCb *>
157 ioCbMap;
158
159 struct SAiosMeta
160 {
161 uint32_t desc;
162 char userDescription[AIOS_USER_DESCRIPTION_MAX];
163 uint8_t numberOfDigitals;
164 SObjectId::ObjectId valueTriggerSettingObjid;
165 SObjectId::ObjectId timeTriggerSettingObjid;
166 uint8_t presentationFormat[AIOS_PRESENTATION_FORMAT_SIZE];
167 uint16_t extendedProperties;
168 };
169
170 struct SAiosDscField
171 {
172 CIOCommon *io;
173 io_ddata_t *data;
174 };
175
176 struct SAiosDscCb
177 {
178 uint8_t kind;
179 uint8_t len;
180 uint8_t data[AIOS_RAW_DESCRIPTOR_MAX];
181 SAiosDscField field;
182 };
183
184 std::map<const SObjectId::ObjectId, SAiosMeta> ioMetaMap;
185
186#ifdef CONFIG_DAWN_IO_NOTIFY
187 static int notifierCb(void *priv, io_ddata_t *data);
188#endif
189
190 static int descriptorCb(uint16_t conn_handle,
191 uint16_t attr_handle,
192 struct ble_gatt_access_ctxt *ctxt,
193 void *arg);
194
195 static int callbackAnalog(uint16_t conn_handle,
196 uint16_t attr_handle,
197 struct ble_gatt_access_ctxt *ctxt,
198 void *arg);
199
200 static int callbackDigital(uint16_t conn_handle,
201 uint16_t attr_handle,
202 struct ble_gatt_access_ctxt *ctxt,
203 void *arg);
204
205 static int callbackAggregate(uint16_t conn_handle,
206 uint16_t attr_handle,
207 struct ble_gatt_access_ctxt *ctxt,
208 void *arg);
209
210 int appendAggregateValue(struct os_mbuf *om);
211 int allocAIOS();
212 int createAIOS();
213 void deleteAIOS();
214 void configureDesc(const SObjectCfg::SObjectCfgItem *item);
215 void allocObject(const SProtoNimblePrphIOBindAiosObjid &obj, const uint32_t *ext);
216 int configureDescriptors(struct ble_gatt_chr_def *chr, SObjectId::ObjectId objid);
217};
218} // Namespace dawn
Automation I/O Service (AIOS) for BLE Peripheral.
Definition prph_aios.hxx:27
int stop()
Stop service.
int deinit()
Deinitialize service.
@ PRPH_AIOS_TYPE_ANALOG
Analog I/O (ADC, DAC).
Definition prph_aios.hxx:60
@ PRPH_AIOS_TYPE_DIGITAL
Digital I/O (GPIO, buttons, LEDs).
Definition prph_aios.hxx:59
int start()
Start service.
int init()
Initialize service.
@ AIOS_EXT_VALUE_TRIGGER_SETTING
Value Trigger Setting descriptor.
Definition prph_aios.hxx:67
@ AIOS_EXT_TIME_TRIGGER_SETTING
Time Trigger Setting descriptor.
Definition prph_aios.hxx:68
@ AIOS_EXT_NUMBER_OF_DIGITALS
Number of Digitals descriptor.
Definition prph_aios.hxx:66
@ AIOS_EXT_EXTENDED_PROPERTIES
Characteristic Extended Properties descriptor.
Definition prph_aios.hxx:70
@ AIOS_EXT_USER_DESCRIPTION
Characteristic User Description descriptor.
Definition prph_aios.hxx:65
@ AIOS_EXT_PRESENTATION_FORMAT
Characteristic Presentation Format descriptor.
Definition prph_aios.hxx:69
Base interface for GATT services exposed by BLE peripheral.
Definition iprph.hxx:467
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218