Loading...
Searching...
No Matches
Go to the documentation of this file.
74#ifndef SLS_AVR_GPIO_H_
75#define SLS_AVR_GPIO_H_
78# error "Include <sls-avr/avr.h> instead of this file."
84#define MAKE_PORT_NAME(_p) MAKE_GLUE_X2(PORT, _p)
86#define MAKE_DDR_NAME(_p) MAKE_GLUE_X2(DDR, _p)
88#define MAKE_PIN_NAME(_p) MAKE_GLUE_X2(PIN, _p)
91#define MAKE_MASK_x0 0x00
93#define MAKE_MASK_x1 _BV
95#define MAKE_MASK_x2(_b1, _b2) (_BV((_b1)) | _BV((_b2)))
97#define MAKE_MASK_x3(_b1, _b2, _b3) (_BV((_b1)) | _BV((_b2)) | _BV((_b3)))
99#define MAKE_MASK_x4(_b1, _b2, _b3, _b4) (_BV((_b1)) | _BV((_b2)) | _BV((_b3)) | _BV((_b4)))
101#define MAKE_MASK_x5(_b1, _b2, _b3, _b4, _b5) (_BV((_b1)) | _BV((_b2)) | _BV((_b3)) | _BV((_b4)) | _BV((_b5)))
103#define MAKE_MASK_x6(_b1, _b2, _b3, _b4, _b5, _b6) (_BV((_b1)) | _BV((_b2)) | _BV((_b3)) | _BV((_b4)) | _BV((_b5)) | _BV((_b6)))
105#define MAKE_MASK_x7(_b1, _b2, _b3, _b4, _b5, _b6, _b7) (_BV((_b1)) | _BV((_b2)) | _BV((_b3)) | _BV((_b4)) | _BV((_b5)) | _BV((_b6)) | _BV((_b7)))
107#define MAKE_MASK_x8 0xFF
116#define gpio_init(_ddr, _val) ((_ddr) = (_val))
117#define GPIO_INIT(_p, _val) gpio_init(MAKE_DDR_NAME(_p), (_val))
123#define gpio_set(_port, _val) ((_port) = (_val))
124#define GPIO_SET(_p, _val) gpio_set(MAKE_PORT_NAME(_p), (_val))
130#define gpio_switch(_port) ((_port) = ~(_port))
131#define GPIO_SWITCH(_p) gpio_switch(MAKE_PORT_NAME(_p))
138#define gpio_byte(_pin) (_pin)
139#define GPIO_BYTE(_p) gpio_byte(MAKE_PIN_NAME(_p))
144#define gpio_set_in(_ddr) gpio_init((_ddr), 0x00);
145#define GPIO_SET_IN(_p) gpio_set_in(MAKE_DDR_NAME(_p))
151#define gpio_set_in_z(_ddr, _port) gpio_set_in((_ddr)); gpio_set_lo((_port))
152#define GPIO_SET_IN_Z(_p) gpio_set_in_z(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
158#define gpio_set_in_pu(_ddr, _port) gpio_set_in((_ddr)); gpio_pull_up((_port))
159#define GPIO_SET_IN_PU(_p) gpio_set_in_pu(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
164#define gpio_set_out(_ddr) gpio_init((_ddr), 0xFF);
165#define GPIO_SET_OUT(_p) gpio_set_out(MAKE_DDR_NAME(_p))
173#define gpio_set_out_d_lo(_ddr, _port) gpio_set_out((_ddr)); gpio_set_lo((_port))
174#define GPIO_SET_OUT_D_LO(_p) gpio_set_out_d_lo(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
182#define gpio_set_out_d_hi(_ddr, _port) gpio_set_out((_ddr)); gpio_set_hi((_port))
183#define GPIO_SET_OUT_D_HI(_p) gpio_set_out_d_hi(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
190#define gpio_set_hi(_port) gpio_set((_port), 0xFF)
191#define GPIO_SET_HI(_p) gpio_set_hi(MAKE_PORT_NAME(_p))
198#define gpio_set_lo(_port) gpio_set((_port), 0x00)
199#define GPIO_SET_LO(_p) gpio_set_lo(MAKE_PORT_NAME(_p))
204#define gpio_read gpio_byte
205#define GPIO_READ GPIO_BYTE
207#define read_byte gpio_byte
208#define READ_BYTE GPIO_BYTE
210#define gpio_to_read gpio_set_in
211#define GPIO_TO_READ GPIO_SET_IN
213#define gpio_to_read_z gpio_set_in_z
214#define GPIO_TO_READ_Z GPIO_SET_IN_Z
216#define gpio_to_read_pu gpio_set_in_pu
217#define GPIO_TO_READ_PU GPIO_SET_IN_PU
219#define gpio_pull_up gpio_set_hi
220#define GPIO_PULL_UP GPIO_SET_HI
222#define gpio_to_write gpio_set_out
223#define GPIO_TO_WRITE GPIO_SET_OUT
225#define gpio_to_write_d_lo gpio_set_out_d_lo
226#define GPIO_TO_WRITE_D_LO GPIO_SET_OUT_D_LO
228#define gpio_to_write_d_hi gpio_set_out_d_hi
229#define GPIO_TO_WRITE_D_HI GPIO_SET_OUT_D_HI
231#define gpio_write gpio_set
232#define GPIO_WRITE GPIO_SET
234#define write_byte gpio_set
235#define WRITE_BYTE GPIO_SET
240#define port_set_in(_ddr, _pinset) ((_ddr) &= ~(_pinset))
241#define PORT_SET_IN(_p, _pinset) port_set_in(MAKE_DDR_NAME(_p), (_pinset))
243#define port_set_out(_ddr, _pinset) ((_ddr) |= (_pinset))
244#define PORT_SET_OUT(_p, _pinset) port_set_out(MAKE_DDR_NAME(_p), (_pinset))
246#define port_set(_port, _pinset) ((_port) |= (_pinset))
247#define PORT_SET(_p, _pinset) port_set(MAKE_PORT_NAME(_p), (_pinset))
249#define port_clear(_port, _pinset) ((_port) &= ~(_pinset))
250#define PORT_CLEAR(_p, _pinset) port_clear(MAKE_PORT_NAME(_p), (_pinset))
252#define port_switch(_port, _pinset) ((_port) ^= (_pinset))
253#define PORT_SWITCH(_p, _pinset) port_switch(MAKE_PORT_NAME(_p), (_pinset))
255#define port_replace(_port, _pinset, _val) ((_port) = ((_port) & (~(_pinset))) | ((_val) & (_pinset)))
256#define PORT_REPLACE(_p, _pinset, _val) port_replace(MAKE_PORT_NAME(_p), (_pinset), (_val))
258#define port_read(_pin, _pinset) (read_byte((_pin)) & (_pinset))
259#define PORT_READ(_p, _pinset) port_read(MAKE_PIN_NAME(_p), (_pinset))
261#define port_set_in_z(_ddr, _port, _pinset) port_set_in((_ddr), (_pinset)); port_clear((_port), (_pinset))
262#define PORT_SET_IN_Z(_p, _pinset) port_set_in_z(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_pinset))
264#define port_set_in_pu(_ddr, _port, _pinset) port_set_in((_ddr), (_pinset)); port_pull_up((_port), (_pinset))
265#define PORT_SET_IN_PU(_p, _pinset) port_set_in_pu(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_pinset))
267#define port_set_out_d_lo(_ddr, _port, _pinset) port_set_out((_ddr), (_pinset)); port_clear((_port), (_pinset))
268#define PORT_SET_OUT_D_LO(_p, _pinset) port_set_out_d_lo(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_pinset))
270#define port_set_out_d_hi(_ddr, _port, _pinset) port_set_out((_ddr), (_pinset)); port_set((_port), (_pinset))
271#define PORT_SET_OUT_D_HI(_p, _pinset) port_set_out_d_hi(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_pinset))
276#define port_set_hi port_set
277#define PORT_SET_HI PORT_SET
279#define port_pull_up port_set
280#define PORT_PULL_UP PORT_SET
282#define port_set_lo port_clear
283#define PORT_SET_LO PORT_CLEAR
285#define port_to_read port_set_in
286#define PORT_TO_READ PORT_SET_IN
288#define port_to_read_pu port_set_in_pu
289#define PORT_TO_READ_PU PORT_SET_IN_PU
291#define port_to_read_z port_set_in_z
292#define PORT_TO_READ_Z PORT_SET_IN_Z
294#define port_to_write port_set_out
295#define PORT_TO_WRITE PORT_SET_OUT
297#define port_write port_replace
298#define PORT_WRITE PORT_REPLACE
300#define port_to_write_d_lo port_set_out_d_lo
301#define PORT_TO_WRITE_D_LO PORT_SET_OUT_D_LO
303#define port_to_write_d_hi port_set_out_d_hi
304#define PORT_TO_WRITE_D_HI PORT_SET_OUT_D_HI
306#define NIBBLE_LO_PINSET 0x0F
308#define nibble_lo_set_in(_ddr) port_set_in((_ddr), NIBBLE_LO_PINSET)
309#define NIBBLE_LO_SET_IN(_p) nibble_lo_set_in(MAKE_DDR_NAME(_p))
311#define nibble_lo_set_out(_ddr) port_set_out((_ddr), NIBBLE_LO_PINSET)
312#define NIBBLE_LO_SET_OUT(_p) nibble_lo_set_out(MAKE_DDR_NAME(_p))
314#define nibble_lo_set(_port) port_set((_port), NIBBLE_LO_PINSET)
315#define NIBBLE_LO_SET(_p) nibble_lo_set(MAKE_PORT_NAME(_p))
317#define nibble_lo_clear(_port) port_clear((_port), NIBBLE_LO_PINSET)
318#define NIBBLE_LO_CLEAR(_p) nibble_lo_clear(MAKE_PORT_NAME(_p))
320#define nibble_lo_switch(_port) port_switch((_port), NIBBLE_LO_PINSET)
321#define NIBBLE_LO_SWITCH(_p) nibble_lo_switch(MAKE_PORT_NAME(_p)))
323#define nibble_lo_replace(_port, _val) port_replace(MAKE_PORT_NAME(_p), NIBBLE_LO_PINSET, (_val))
324#define NIBBLE_LO_REPLACE(_p, _val) nibble_lo_replace(MAKE_PORT_NAME(_p), (_val))
326#define nibble_lo_read(_pin) port_read((_pin), (NIBBLE_LO_PINSET))
327#define NIBBLE_LO_READ(_p) nibble_lo_read(MAKE_PIN_NAME(_p))
329#define nibble_lo_set_in_z(_ddr, _port) port_set_in_z((_ddr), (_port), NIBBLE_LO_PINSET)
330#define NIBBLE_LO_SET_IN_Z(_p) nibble_lo_set_in_z(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
332#define nibble_lo_set_in_pu(_ddr, _port) port_set_in_pu((_ddr), (_port), NIBBLE_LO_PINSET)
333#define NIBBLE_LO_SET_IN_PU(_p) nibble_lo_set_in_pu(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
335#define nibble_lo_set_out_d_lo(_ddr, _port) port_set_out_d_lo((_ddr), (_port), NIBBLE_LO_PINSET)
336#define NIBBLE_LO_SET_OUT_D_LO(_p) nibble_lo_set_out_d_lo(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
338#define nibble_lo_set_out_d_hi(_ddr, _port) port_set_out_d_hi((_ddr), (_port), NIBBLE_LO_PINSET)
339#define NIBBLE_LO_SET_OUT_D_HI(_p) nibble_lo_set_out_d_hi(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
344#define nibble_lo_set_hi nibble_lo_set
345#define NIBBLE_LO_SET_HI NIBBLE_LO_SET
347#define nibble_lo_pull_up nibble_lo_set
348#define NIBBLE_LO_PULL_UP NIBBLE_LO_SET
350#define nibble_lo_set_lo nibble_lo_clear
351#define NIBBLE_LO_SET_LO NIBBLE_LO_CLEAR
353#define nibble_lo_to_read nibble_lo_set_in
354#define NIBBLE_LO_TO_READ NIBBLE_LO_SET_IN
356#define nibble_lo_to_read_pu nibble_lo_set_in_pu
357#define NIBBLE_LO_TO_READ_PU NIBBLE_LO_SET_IN_PU
359#define nibble_lo_to_read_z nibble_lo_set_in_z
360#define NIBBLE_LO_TO_READ_Z NIBBLE_LO_SET_IN_Z
362#define nibble_lo_to_write nibble_lo_set_out
363#define NIBBLE_LO_TO_WRITE NIBBLE_LO_SET_OUT
365#define nibble_lo_write nibble_lo_replace
366#define NIBBLE_LO_WRITE NIBBLE_LO_REPLACE
368#define nibble_lo_to_write_d_lo nibble_lo_set_out_d_lo
369#define NIBBLE_LO_TO_WRITE_D_LO NIBBLE_LO_SET_OUT_D_LO
371#define nibble_lo_to_write_d_hi nibble_lo_set_out_d_hi
372#define NIBBLE_LO_TO_WRITE_D_HI NIBBLE_LO_SET_OUT_D_HI
374#define NIBBLE_UP_PINSET 0xF0
376#define nibble_up_set_in(_ddr) port_set_in((_ddr), NIBBLE_UP_PINSET)
377#define NIBBLE_UP_SET_IN(_p) nibble_up_set_in(MAKE_DDR_NAME(_p))
379#define nibble_up_set_out(_ddr) port_set_out((_ddr), NIBBLE_UP_PINSET)
380#define NIBBLE_UP_SET_OUT(_p) nibble_up_set_out(MAKE_DDR_NAME(_p))
382#define nibble_up_set(_port) port_set((_port), NIBBLE_UP_PINSET)
383#define NIBBLE_UP_SET(_p) nibble_up_set(MAKE_PORT_NAME(_p))
385#define nibble_up_clear(_port) port_clear((_port), NIBBLE_UP_PINSET)
386#define NIBBLE_UP_CLEAR(_p) nibble_up_clear(MAKE_PORT_NAME(_p))
388#define nibble_up_switch(_port) port_switch((_port), NIBBLE_UP_PINSET)
389#define NIBBLE_UP_SWITCH(_p) nibble_up_switch(MAKE_PORT_NAME(_p)))
391#define nibble_up_replace(_port, _val) port_replace(MAKE_PORT_NAME(_p), NIBBLE_UP_PINSET, (_val))
392#define NIBBLE_UP_REPLACE(_p, _val) nibble_up_replace(MAKE_PORT_NAME(_p), (_val))
394#define nibble_up_read(_pin) port_read((_pin), (NIBBLE_UP_PINSET))
395#define NIBBLE_UP_READ(_p) nibble_up_read(MAKE_PIN_NAME(_p))
397#define nibble_up_set_in_z(_ddr, _port) port_set_in_z((_ddr), (_port), NIBBLE_UP_PINSET)
398#define NIBBLE_UP_SET_IN_Z(_p) nibble_up_set_in_z(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
400#define nibble_up_set_in_pu(_ddr, _port) port_set_in_pu((_ddr), (_port), NIBBLE_UP_PINSET)
401#define NIBBLE_UP_SET_IN_PU(_p) nibble_up_set_in_pu(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
403#define nibble_up_set_out_d_lo(_ddr, _port) port_set_out_d_lo((_ddr), (_port), NIBBLE_UP_PINSET)
404#define NIBBLE_UP_SET_OUT_D_LO(_p) nibble_up_set_out_d_lo(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
406#define nibble_up_set_out_d_hi(_ddr, _port) port_set_out_d_hi((_ddr), (_port), NIBBLE_UP_PINSET)
407#define NIBBLE_UP_SET_OUT_D_HI(_p) nibble_up_set_out_d_hi(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p))
412#define nibble_up_set_hi nibble_up_set
413#define NIBBLE_UP_SET_HI NIBBLE_UP_SET
415#define nibble_up_pull_up nibble_up_set
416#define NIBBLE_UP_PULL_UP NIBBLE_UP_SET
418#define nibble_up_set_lo nibble_up_clear
419#define NIBBLE_UP_SET_LO NIBBLE_UP_CLEAR
421#define nibble_up_to_read nibble_up_set_in
422#define NIBBLE_UP_TO_READ NIBBLE_UP_SET_IN
424#define nibble_up_to_read_pu nibble_up_set_in_pu
425#define NIBBLE_UP_TO_READ_PU NIBBLE_UP_SET_IN_PU
427#define nibble_up_to_read_z nibble_up_set_in_z
428#define NIBBLE_UP_TO_READ_Z NIBBLE_UP_SET_IN_Z
430#define nibble_up_to_write nibble_up_set_out
431#define NIBBLE_UP_TO_WRITE NIBBLE_UP_SET_OUT
433#define nibble_up_write nibble_up_replace
434#define NIBBLE_UP_WRITE NIBBLE_UP_REPLACE
436#define nibble_up_to_write_d_lo nibble_up_set_out_d_lo
437#define NIBBLE_UP_TO_WRITE_D_LO NIBBLE_UP_SET_OUT_D_LO
439#define nibble_up_to_write_d_hi nibble_up_set_out_d_hi
440#define NIBBLE_UP_TO_WRITE_D_HI NIBBLE_UP_SET_OUT_D_HI
445#define pin_set_in(_ddr, _b) port_set_in((_ddr), _BV((_b)))
446#define PIN_SET_IN(_p, _b) pin_set_in(MAKE_DDR_NAME(_p), (_b))
448#define pin_set_out(_ddr, _b) port_set_out((_ddr), _BV((_b)))
449#define PIN_SET_OUT(_p, _b) pin_set_out(MAKE_DDR_NAME(_p), (_b))
451#define pin_set(_port, _b) port_set((_port), _BV((_b)))
452#define PIN_SET(_p, _b) pin_set(MAKE_PORT_NAME(_p), (_b))
454#define pin_clear(_port, _b) port_clear((_port), _BV((_b)))
455#define PIN_CLEAR(_p, _b) pin_clear(MAKE_PORT_NAME(_p), (_b))
457#define pin_switch(_port, _b) port_switch((_port), _BV((_b)))
458#define PIN_SWITCH(_p, _b) pin_switch(MAKE_PORT_NAME(_p), (_b))
460#define pin_replace(_port, _b, _val) port_replace((_port), _BV((_b)), (_val))
461#define PIN_REPLACE(_p, _b, _val) pin_replace(MAKE_PORT_NAME(_p), (_b), (_val))
463#define pin_read(_pin, _b) port_read((_pin), (_BV((_b))))
464#define PIN_READ(_p, _b) pin_read(MAKE_PIN_NAME(_p), (_b))
466#define pin_set_in_z(_ddr, _port, _b) port_set_in_z((_ddr), (_port), _BV((_b)))
467#define PIN_SET_IN_Z(_p, _b) pin_set_in_z(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_b))
469#define pin_set_in_pu(_ddr, _port, _b) port_set_in_pu((_ddr), (_port), _BV((_b)))
470#define PIN_SET_IN_PU(_p, _b) pin_set_in_pu(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_b))
472#define pin_set_out_d_lo(_ddr, _port, _b) port_set_out_d_lo((_ddr), (_port), _BV((_b)))
473#define PIN_SET_OUT_D_LO(_p, _b) pin_set_out_d_lo(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_b))
475#define pin_set_out_d_hi(_ddr, _port, _b) port_set_out_d_hi((_ddr), (_port), _BV((_b)))
476#define PIN_SET_OUT_D_HI(_p, _b) pin_set_out_d_hi(MAKE_DDR_NAME(_p), MAKE_PORT_NAME(_p), (_b))
481#define pin_set_hi pin_set
482#define PIN_SET_HI PIN_SET
484#define pin_on pin_set
485#define PIN_ON PIN_SET
487#define pin_pull_up pin_set
488#define PIN_PULL_UP PIN_SET
490#define pin_set_lo pin_clear
491#define PIN_SET_LO PIN_CLEAR
493#define pin_off pin_clear
494#define PIN_OFF PIN_CLEAR
496#define pin_to_read pin_set_in
497#define PIN_TO_READ PIN_SET_IN
499#define pin_to_read_pu pin_set_in_pu
500#define PIN_TO_READ_PU PIN_SET_IN_PU
502#define pin_to_read_z pin_set_in_z
503#define PIN_TO_READ_Z PIN_SET_IN_Z
505#define pin_to_write pin_set_out
506#define PIN_TO_WRITE PIN_SET_OUT
508#define pin_write pin_replace
509#define PIN_WRITE PIN_REPLACE
511#define pin_to_write_d_lo pin_set_out_d_lo
512#define PIN_TO_WRITE_D_LO PIN_SET_OUT_D_LO
514#define pin_to_write_d_hi pin_set_out_d_hi
515#define PIN_TO_WRITE_D_HI PIN_SET_OUT_D_HI