HWA
Bare metal programming with style
pcf8574.h
Go to the documentation of this file.
1
2
/* This file is part of the HWA project.
3
* Copyright (c) 2018 Christophe Duparquet.
4
* All rights reserved. Read LICENSE.TXT for details.
5
*/
6
62
#define hw_class__pcf8574
63
70
#define HW_PCF8574(...) _HW_PCF8574_(__VA_ARGS__,,,,,)
71
#define _HW_PCF8574_(k,...) HW_BW(_HW_PCF8574_1_,interface,k)(k,__VA_ARGS__)
72
#define _HW_PCF8574_1_0(...) _HW_PCF8574_E
73
#define _HW_PCF8574_1_1(k,...) _HW_PCF8574_1_2(HW_ANAME(__VA_ARGS__))
74
#define _HW_PCF8574_1_2(...) _HW_PCF8574_1_3(__VA_ARGS__)
75
#define _HW_PCF8574_1_3(twi,k,...) HW_BW(_HW_PCF8574_2_,address,k)(twi,k,__VA_ARGS__)
76
#define _HW_PCF8574_2_0(...) _HW_PCF8574_E
77
#define _HW_PCF8574_2_1(twi,k,sla,...) _pcf8574,pcf8574_##twi##_##sla,(twi,sla) HW_EOL(__VA_ARGS__)
78
79
#define _HW_PCF8574_E HW_E(HW_EM_SY("HW_PCF8574(interface,..., address,...)"))
80
81
82
#define HW_DECLARE__pcf8574 , _hw_dcpcf8574
83
84
#define _hw_dcpcf8574(o,twi,sla,...) HW_BV(_hw_dcpcf8574,declare_,HW_A0(__VA_ARGS__),o,twi,sla)
85
#define _hw_dcpcf85740(v,...) HW_E(HW_EM_OVL(v,(weak)))
86
#define _hw_dcpcf85741(weak,o,twi,sla) \
87
\
88
extern uint8_t _hw_##o##_reg ; \
89
\
90
HW_INLINE weak uint8_t _hw_##o##_read ( ) \
91
{ \
92
return _hw_##twi##_start_read_stop(sla); \
93
} \
94
\
95
HW_INLINE weak uint8_t _hw_##o##_read_np ( uint8_t n, uint8_t p ) \
96
{ \
97
if ( (p+n)>8 ) HWA_E(HW_EM(o can not access bits outside 0..7)); \
98
return (_hw_##twi##_start_read_stop(sla)>>p) & ((1U<<n)-1); \
99
} \
100
\
101
HW_INLINE weak void _hw_##o##_writea_np ( uint8_t n, uint8_t p, uint8_t v ) \
102
{ \
103
if ( (p+n)>8 ) HWA_E(HW_EM(o can not access bits outside 0..7)); \
104
_hw_##o##_reg = (_hw_##o##_reg & ~(((1U<<n)-1)<<p)) | (v<<p) ; \
105
} \
106
\
107
HW_INLINE weak void _hw_##o##_togglea_np ( uint8_t n, uint8_t p ) \
108
{ \
109
if ( (p+n)>8 ) HWA_E(HW_EM(o can not access bits outside 0..7)); \
110
_hw_##o##_reg = _hw_##o##_reg ^ (((1U<<n)-1)<<p) ; \
111
} \
112
\
113
HW_INLINE weak void _hw_##o##_commit ( ) \
114
{ \
115
_hw_##twi##_start_write_stop(sla,_hw_##o##_reg); \
116
} \
117
\
118
HW_INLINE weak void _hw_##o##_write ( uint8_t v ) \
119
{ \
120
_hw_##o##_reg = v ; \
121
_hw_##o##_commit(); \
122
} \
123
\
124
HW_INLINE weak void _hw_##o##_write_np ( uint8_t n, uint8_t p, uint8_t v ) \
125
{ \
126
_hw_##o##_writea_np(n,p,v) ; \
127
_hw_##o##_commit(); \
128
} \
129
\
130
HW_INLINE weak void _hw_##o##_toggle_np ( uint8_t n, uint8_t p ) \
131
{ \
132
_hw_##o##_togglea_np(n,p) ; \
133
_hw_##o##_commit(); \
134
} \
135
\
136
extern uint8_t hw_foo()
137
138
139
#define HW_IMPLEMENT__pcf8574 , _hw_define_pcf8574_
140
141
#define _hw_define_pcf8574_(o,sla,twi,...) _hw_define_pcf8574(o,sla,twi,,__VA_ARGS__)
142
#define _hw_define_pcf8574w(o,sla,twi,...) _hw_define_pcf8574(o,sla,twi,__attribute__((weak)),__VA_ARGS__)
143
#define _hw_define_pcf8574(o,sla,twi,attr,...) uint8_t attr _hw_##o##_reg
144
145
181
#define hw_configure__pcf8574 , _hw_cfpcf8574
182
#define hwa_configure__pcf8574 , _hwa_cfpcf8574
183
184
#define _hw_cfpcf8574(o,sla,twi,...) _hwx_cfpcf8574(o,sla,twi,__VA_ARGS__)
185
#define _hwa_cfpcf8574(o,sla,twi,...) _hwx_cfpcf8574(o,sla,twi,__VA_ARGS__)
186
#define _hwx_cfpcf8574(o,sla,twi,...) _hw_##o##_reg = 0xFF HW_EOL(__VA_ARGS__)
187
188
204
#define hw_read__pcf8574 , _hw_rdpcf8574
205
#define _hw_rdpcf8574(o,sla,twi,...) _hw_##o##_read()
206
207
#define hw_write__pcf8574 , _hw_wrpcf8574
208
#define _hw_wrpcf8574(o,sla,twi,v,...) _hw_##o##_write(v)
209
210
#define hw_commit__pcf8574 , _hw_commit_pcf8574
211
#define _hw_commit_pcf8574(o,sla,twi,...) _hw_##o##_commit()
212
213
218
#define hw_class__io8574
219
220
221
/* Accept to append a number to a _pcf8574 definition so that
222
* '(pcf,n)' designates a single pin at position n of pcf, of class _io8574.
223
*
224
* Validity of n is verified by functions.
225
*/
226
#define hw__pcf8574_ , _hw_pcf8574_
227
#define _hw_pcf8574_(o,n,twi,sla) _HW_B(_hw_pcf8574_,_hw_isa_4bn_##n)(o,n)
228
#define _hw_pcf8574_1(o,n) _io8574,o,(1,n)
229
#define _hw_pcf8574_0(o,n) ,o,HW_EM(o has no relative n)
230
231
232
/* Accept to append a number to a _io8574 definition so that '(pcf,n,p)'
233
* designates a set of n consecutive pins at position p of pcf.
234
*
235
* Validity of n and p is verified by functions.
236
*/
237
#define hw__io8574_ , _hw_io8574_
238
#define _hw_io8574_(o,r,bn,bp) _HW_B(_hw_io8574_,_hw_is_1_##bn)(o,r,bn,bp)
239
#define _hw_io8574_0(o,r,...) ,o,HW_EM(o has no relative r)
240
#define _hw_io8574_1(o,r,bn,bp) _HW_B(_hw_io85741_,_hw_isa_4bn_##r)(o,r,bn,bp)
241
#define _hw_io85741_1(o,r,bn,bp) _io8574,o,(bp,r)
242
#define _hw_io85741_0(o,r,bn,bp) ,o,HW_EM(o has no relative r)
243
244
245
#define HW_BITS__io8574 , _hw_bits_io8574
246
#define _hw_bits_io8574(o,n,p,...) n
247
248
#define hw__io8574_port , _hw_io8574_port
249
#define _hw_io8574_port(o,...) _pcf8574,o,()
250
251
#define hw_read__io8574 , _hw_rdio8574
252
#define _hw_rdio8574(o,bn,bp,v,...) _hw_##o##_read_np(bn,bp)
253
254
#define hw_write__io8574 , _hw_wrio8574
255
#define _hw_wrio8574(o,bn,bp,v,...) _hw_##o##_write_np(bn,bp,v)
256
257
#define hw_toggle__io8574 , _hw_tgio8574
258
#define _hw_tgio8574(o,bn,bp,...) _hw_##o##_toggle_np(bn,bp)
259
260
#define hw_set__io8574 , _hw_w1io8574
261
#define _hw_w1io8574(o,bn,bp,...) _hw_##o##_write_np(bn,bp,((1U<<bn)-1))
262
263
#define hw_clear__io8574 , _hw_w0io8574
264
#define _hw_w0io8574(o,bn,bp,...) _hw_##o##_write_np(bn,bp,0)
265
266
#define hw_writea__io8574 , _hw_pcf8574iowra
267
#define _hw_pcf8574iowra(o,bn,bp,v,...) _hw_##o##_writea_np(bn,bp,v)
268
269
#define hwa_write__io8574 , _hwa_pcf8574iowr
270
#define _hwa_pcf8574iowr(o,bn,bp,v,...) _hw_##o##_writea_np(bn,bp,v)
271
272
/* #define hwa_write__io8574 , _hwa_wrio8574 */
273
/* #define _hwa_wrio8574(o,bn,bp,v,...) \ */
274
/* do{ uint8_t msk = ((1U<<bn)-1)<<bp ; \ */
275
/* _hw_##o##_value = (_hw_##o##_value & ~msk) | (v & msk) ; \ */
276
/* _hw_##o##_mask |= msk ; \ */
277
/* }while(0) */
Generated for HWA by
1.8.6