108 #if defined(NO_LEDS) || defined (DOXYGEN)
111 # define LED_NUMBER (0)
114 #if defined(NO_LEDS) || defined (DOXYGEN)
116 # define LED_INIT() do{}while(0)
117 #elif !defined(LED_INIT)
118 # if LEDS_INVERSE == 0
119 # define LED_INIT() do{\
120 LED_DDR |= (LED_MASK); LED_PORT &= ~(LED_MASK);\
123 # define LED_INIT() do{\
124 LED_DDR |= (LED_MASK); LED_PORT |= (LED_MASK);\
129 #if defined(NO_LEDS) || defined (DOXYGEN)
135 # define LED_SET_VALUE(x) do{}while(0)
136 #elif !defined(LED_SET_VALUE)
137 # if LEDS_INVERSE == 0
138 # define LED_SET_VALUE(x) \
140 LED_PORT = (LED_PORT & ~LED_MASK) | ((x<<LED_SHIFT) & LED_MASK);\
143 # define LED_SET_VALUE(x) do {\
144 LED_PORT = (LED_PORT & ~LED_MASK) | ((~x<<LED_SHIFT) & LED_MASK);\
149 #if defined(NO_LEDS) || defined (DOXYGEN)
151 # define LED_GET_VALUE() 0
152 #elif !defined(LED_GET_VALUE)
153 # if LEDS_INVERSE == 0
154 # define LED_GET_VALUE() ((LED_PORT & LED_MASK) >> LED_SHIFT)
156 # define LED_GET_VALUE() ((~LED_PORT & LED_MASK) >> LED_SHIFT)
161 #if defined(NO_LEDS) || defined (DOXYGEN)
163 # define LED_SET(ln) do{}while(0)
164 #elif !defined(LED_SET)
165 # if LEDS_INVERSE == 0
166 # define LED_SET(ln) LED_PORT |= (_BV(ln+LED_SHIFT) & LED_MASK)
168 # define LED_SET(ln) LED_PORT &= ~(_BV(ln+LED_SHIFT) & LED_MASK)
173 #if defined(NO_LEDS) || defined (DOXYGEN)
175 # define LED_CLR(ln) do{}while(0)
176 #elif !defined(LED_CLR)
177 # if LEDS_INVERSE == 0
178 # define LED_CLR(ln) LED_PORT &= ~(_BV(ln+LED_SHIFT) & LED_MASK)
180 # define LED_CLR(ln) LED_PORT |= (_BV(ln+LED_SHIFT) & LED_MASK)
184 #if defined(NO_LEDS) || defined (DOXYGEN)
186 # define LED_VAL(msk,val) do{}while(0)
187 #elif !defined(LED_VAL)
188 # if LEDS_INVERSE == 0
189 # define LED_VAL(msk,val) LED_PORT |= ((LED_MASK|msk) << LED_SHIFT); \
190 LED_PORT |= ~((val << LED_SHIFT)& (LED_MASK|(msk<<LED_SHIFT)) )
192 # define LED_VAL(msk,val) LED_PORT &= ~(LED_MASK|(msk<<LED_SHIFT)); LED_PORT |= ~(val & (LED_MASK|msk))
197 #if defined(NO_LEDS) || defined (DOXYGEN)
199 # define LED_TOGGLE(ln) do{}while(0)
200 #elif !defined(LED_TOGGLE)
201 # define LED_TOGGLE(ln) LED_PORT ^= (_BV(ln+LED_SHIFT) & LED_MASK)
205 #define LED_MAX_VALUE ((1<<LED_NUMBER)-1)
216 #if defined(NO_KEYS) || defined (DOXYGEN)
221 # define KEY_GET() (0)
224 # if PULLUP_KEYS != 0
225 # define PULL_MASK (MASK_KEY)
227 # define PULL_MASK (0)
229 # if !defined KEY_INIT
230 # define KEY_INIT() do{PORT_KEY |= PULL_MASK; DDR_KEY &= ~(MASK_KEY); }while(0)
232 # if !defined KEY_GET
233 # if INVERSE_KEYS == 0
235 ((PIN_KEY & MASK_KEY) >> SHIFT_KEY)
238 ((~PIN_KEY & MASK_KEY) >> SHIFT_KEY)
251 static uint8_t key_state;
252 static uint8_t ct0, ct1;
269 ct1 = (ct0 ^ ct1) & i;
278 return key_state & i;
307 #if BOOTLOADER_ADDRESS != 0
309 #define JUMP_BOOT_LOADER() \
311 void (*funcptr)( uint8_t flag ) = BOOTLOADER_ADDRESS;\
315 #define JUMP_BOOT_LOADER()
330 #define BUFFER_SET_USED(b) do{ATOMIC_BLOCK(ATOMIC_FORCEON){b->used|=1}}while(0)
331 #define BUFFER_SET_UNUSED(b) do{ATOMIC_BLOCK(ATOMIC_FORCEON){b->used&=~1}}while(0)
332 #define BUFFER_IS_USED(b) ((b->used&1)!=0)
334 #define BUFFER_SET_LOCK(b) do{ATOMIC_BLOCK(ATOMIC_FORCEON){b->used|=2}}while(0)
335 #define BUFFER_SET_UNLOCK(b) do{ATOMIC_BLOCK(ATOMIC_FORCEON){b->used&=~2}}while(0)
336 #define BUFFER_IS_LOCKED(b) ((b->used&2)!=0)
339 #define BUFFER_SET_USED(b) do{b->used|=1;}while(0)
340 #define BUFFER_SET_UNUSED(b) do{b->used&=~1;}while(0)
341 #define BUFFER_IS_USED(b) ((b->used&1)!=0)
343 #define BUFFER_SET_LOCK(b) do{b->used|=2;}while(0)
344 #define BUFFER_SET_UNLOCK(b) do{b->used&=~2;}while(0)
345 #define BUFFER_IS_LOCKED(b) ((b->used&2)!=0)
348 #define BUFFER_SIZE(b) (b->iend - b->istart)
349 #define BUFFER_PDATA(b) (b->data + b->istart)
350 #define BUFFER_SEEK(b,offset) (b->data + (b->iend=offset))
352 #define BUFFER_GET_MEMBLOCK(b,pmem,size) \
355 pmem = (b->data + b->iend);\
356 size = (b->len - b->iend);\
359 #define BUFFER_UPDATE_MEMBLOCK(b,end) \
365 #define BUFFER_LAST_CHAR(b) \
366 (b->iend <= b->istart) ? EOF : (char)b->data[b->iend-1]
367 #define BUFFER_FREE_AT_END(b) (b->len - b->iend)
368 #define BUFFER_FREE_AT_START(b) (b->istart)
369 #define BUFFER_ELSZ(x) (sizeof(buffer_t) + (x))
370 #define BUFFER_RESET(b,start) do{ b->iend = b->istart = start;}while(0)
371 #define BUFFER_ADVANCE(b,more) do{ b->istart += more;}while(0)
389 buffer_pool_t * buffer_pool_init(uint8_t *pmem,
size_t memsz, uint8_t bsz);
390 buffer_t * buffer_alloc(buffer_pool_t *ppool, uint8_t istart);
410 int buffer_stream_init( buffer_stream_t *pbs,
414 int buffer_stream_putchar(
char c,FILE *f);
415 int buffer_stream_getchar(FILE *f);
int buffer_get_char(buffer_t *b)
int buffer_append_char(buffer_t *b, uint8_t c)
uint8_t buffer_append_block(buffer_t *b, void *pdata, uint8_t size)
static uint8_t keys_debounced(void)
Debounce Key values, returned from the macro KEY_GET()
uint8_t buffer_get_block(buffer_t *b, void *pdata, uint8_t size)
uint8_t buffer_prepend_block(buffer_t *b, void *pdata, uint8_t size)
int buffer_prepend_char(buffer_t *b, int c)
buffer_t * buffer_init(void *pmem, uint8_t size, uint8_t start)
#define DELAY_MS(x)
Macro for delays with ms resolution.
static void trap_if_key_pressed(void)
Debounce Key values, returned from the macro KEY_GET()