42 #include "sensor_defs.h"
47 #define LEDPS_DEBUG (0)
50 # define DBG_LEDPS(...) PRINTF(__VA_ARGS__)
52 # define DBG_LEDPS(...)
55 #define DO_LED_PS(port, ddr, pin, anode, cathode, ledps_cnt) \
57 ddr |= (_BV(anode) | _BV(cathode)); \
58 port &= ~_BV(anode); \
59 port |= _BV(cathode); \
62 ddr &= ~_BV(cathode); \
63 port &= ~_BV(cathode); \
67 } while ((pin & _BV(cathode)) && --ledps_cnt);\
69 ddr |= (_BV(anode) | _BV(cathode));\
104 static inline uint16_t
sample_port(
char portid, uint8_t anode_pin, uint8_t cathode_pin);
105 static inline uint16_t
sample_port(
char portid, uint8_t anode_pin, uint8_t cathode_pin)
107 uint16_t rv = 0xffff;
115 #if defined(LEDPS_PORTA) && defined(PORTA)
117 DO_LED_PS(PORTA, DDRA, PINA, anode_pin, cathode_pin, rv);
120 #if defined(LEDPS_PORTB) && defined(PORTB)
122 DO_LED_PS(PORTB, DDRB, PINB, anode_pin, cathode_pin, rv);
125 #if defined(LEDPS_PORTC) && defined(PORTC)
127 DO_LED_PS(PORTC, DDRC, PINC, anode_pin, cathode_pin, rv);
130 #if defined(LEDPS_PORTD) && defined(PORTD)
132 DO_LED_PS(PORTD, DDRD, PIND, anode_pin, cathode_pin, rv);
135 #if defined(LEDPS_PORTE) && defined(PORTE)
137 DO_LED_PS(PORTE, DDRE, PINE, anode_pin, cathode_pin, rv);
140 #if defined(LEDPS_PORTF) && defined(PORTF)
142 DO_LED_PS(PORTF, DDRF, PINF, anode_pin, cathode_pin, rv);
165 p->type = SENSOR_DATA_LIGHT;
166 p->sensor = SENSOR_LEDPS;
181 pdata[1] = SENSOR_LEDPS;
200 char portid, uint8_t panode, uint8_t pcathode)
209 pcfg->g.id = SENSOR_LEDPS;
217 pcfg->panode = panode;
218 pcfg->pcathode = pcathode;
219 DBG_LEDPS(
"ledps: port: %c ano: %d, cath: %d\n",
220 pcfg->
portid, pcfg->panode, pcfg->pcathode);
static void ledps_trigger(void *pctx, bool one_shot)
static uint8_t ledps_get_val(void *pctx, uint8_t *pdata)
#define DO_LED_PS(port, ddr, pin, anode, cathode, ledps_cnt)
static void ledps_sleep(void *pctx)
static uint16_t sample_port(char portid, uint8_t anode_pin, uint8_t cathode_pin)
sample port Note: The following macros needs to be defined in board_.h
static uint8_t ledps_get_raw(void *pctx, uint8_t *pdata)
static uint8_t sensor_create_ledps(void *pdata, bool raw, char portid, uint8_t panode, uint8_t pcathode)