X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/fnordlicht-mini/blobdiff_plain/ec1bef8e19888e982ffc53129f74d58868e8d203..refs/heads/master:/firmware/fnordlicht-firmware/remote.c diff --git a/firmware/fnordlicht-firmware/remote.c b/firmware/fnordlicht-firmware/remote.c index d6f54f7..016a866 100644 --- a/firmware/fnordlicht-firmware/remote.c +++ b/firmware/fnordlicht-firmware/remote.c @@ -45,12 +45,6 @@ #define R_PIN _INPORT(REMOTE_INT_PORT) #define INTPIN REMOTE_INT_PIN -#define M_PORT _OUTPORT(REMOTE_MASTER_PORT) -#define M_DDR _DDRPORT(REMOTE_MASTER_PORT) -#define M_PIN _INPORT(REMOTE_MASTER_PORT) -#define M_PIN1 REMOTE_MASTER_PIN1 -#define M_PIN2 REMOTE_MASTER_PIN2 - struct remote_state_t { /* serial communication */ @@ -63,9 +57,6 @@ struct remote_state_t uint8_t sync; uint8_t synced; struct pt thread; -#if CONFIG_MASTER_MODE - struct pt master_thread; -#endif /* int line */ timer_t int_timer; @@ -98,14 +89,6 @@ static void parse_powerdown(void); void remote_init(void) { - /* master mode check: check if PIN2 pulls down PIN1 */ - /* configure M_PIN1 as input with pullup */ - M_DDR &= ~_BV(M_PIN1); - M_PORT |= _BV(M_PIN1); - /* configure M_PIN2 as output, set low */ - M_DDR |= _BV(M_PIN2); - M_PORT &= ~_BV(M_PIN2); - /* initialize offsets */ global_remote.offsets.saturation = 255; global_remote.offsets.value = 255; @@ -115,17 +98,6 @@ void remote_init(void) R_PORT &= ~_BV(INTPIN); #ifdef INIT_ZERO remote.int_state = INT_IDLE; - - PT_INIT(&remote.master_thread); -#endif - -#if CONFIG_MASTER_MODE == 1 - /* check master state: read value of M_PIN1 */ - if (!(M_PIN & _BV(M_PIN1))) - global_remote.master = true; -#elif CONFIG_MASTER_MODE == 2 - /* statically configure master mode */ - global_remote.master = true; #endif } @@ -209,90 +181,6 @@ static void send_resync(uint8_t addr) uart_putc(addr); } -#if CONFIG_MASTER_MODE -/* parameters for master mode script commands */ -#define MASTER_PROGRAMS 2 -static PROGMEM uint8_t master_parameters[] = { - /* first: colorwheel forward */ - 0, /* program index */ - 1, /* fade step */ - 2, /* fade delay */ - 0, /* fade sleep */ - 0, 0, /* hue start (little endian) */ - 20, 0, /* hue step (little endian) */ - -1, /* addr add */ - 255, /* saturation */ - 255, /* value */ - - /* first: colorwheel backward */ - 0, /* program index */ - 1, /* fade step */ - 2, /* fade delay */ - 0, /* fade sleep */ - 0, 0, /* hue start (little endian) */ - 20, 0, /* hue step (little endian) */ - 1, /* addr add */ - 255, /* saturation */ - 255, /* value */ -}; - -static PT_THREAD(remote_master_thread(struct pt *thread)) -{ - static struct remote_msg_start_program_t msg; - static timer_t timer; - static uint16_t sleep; - static uint8_t *ptr; - static uint8_t idx; - - PT_BEGIN(thread); - - /* wait */ - timer_set(&timer, MASTER_WAIT_BEFORE_SYNC); - while(!timer_expired(&timer)) - PT_YIELD(thread); - - /* start program on all devices */ - msg.address = 0xff; - msg.cmd = REMOTE_CMD_START_PROGRAM; - - while (1) { - ptr = &master_parameters[0]; - - for (idx = 0; idx < MASTER_PROGRAMS; idx++) { - /* stop current program and fading */ - script_stop(); - pwm_stop_fading(); - - /* start program colorwheel on all nodes */ - msg.script = pgm_read_byte(ptr++); - /* load parameters */ - for (uint8_t i = 0; i < sizeof(msg.params); i++) - msg.params.raw[i] = pgm_read_byte(ptr++); - - /* send */ - send_resync(MASTER_MODE_FIRST_ADDRESS); - PT_YIELD(thread); - send_msg((struct remote_msg_t *)&msg); - - /* start program locally */ - script_start(0, msg.script, &msg.params); - - /* sleep */ - sleep = MASTER_MODE_SLEEP; - while (sleep--) { - /* sleep 1s */ - timer_set(&timer, 100); - - while (!timer_expired(&timer)) - PT_YIELD(thread); - } - } - } - - PT_END(thread); -} -#endif - void remote_poll(void) { if (fifo_fill((fifo_t *)&global_uart.rx) > 0) { @@ -310,9 +198,6 @@ void remote_poll(void) /* enable remote command thread */ remote.synced = 1; PT_INIT(&remote.thread); -#if CONFIG_MASTER_MODE - global_remote.master = false; -#endif } else { /* just pass through data */ uart_putc(data); @@ -337,11 +222,6 @@ void remote_poll(void) if (remote.int_state == INT_PULLED_TIMER && timer_expired(&remote.int_timer)) { remote_release_int(); } - -#if CONFIG_MASTER_MODE - if (global_remote.master) - PT_SCHEDULE(remote_master_thread(&remote.master_thread)); -#endif } void remote_pull_int(void) @@ -536,10 +416,15 @@ void parse_config_startup(struct remote_msg_config_startup_t *msg) storage_save_config(); } +#if UART_TX_ENABLED static void wait_for_uart(void) { while (fifo_fill((fifo_t *)&global_uart.tx) != 0 || !uart_send_complete()); } +#else +/* no need to wait for me */ +#define wait_for_uart() +#endif void parse_bootloader(struct remote_msg_bootloader_t *msg) {