6 #define POLARITY PORTD2
8 #define BIT(x) (1<<(x))
16 void output_init(void)
18 DDRD = (DDRD&0xF3)|0x0C;
19 PORTD &= ~BIT(ENABLE);
21 timer_start_hz(2, 80000, 1);
24 void clear_packet(void)
31 void output_set_power(uint8_t p)
36 PORTD &= ~BIT(ENABLE);
39 uint8_t output_command(const uint8_t *cmd_buf, uint8_t cmd_length)
41 if(cmd_buf[0]==POWER_ON || cmd_buf[0]==POWER_OFF)
46 output_set_power(cmd_buf[0]==POWER_ON);
49 return INVALID_COMMAND;
54 static inline void output_tick(void)
56 if(delay_time && --delay_time)
59 if(out_time && !--out_time)
62 if(out_bit>=packet.length)
64 PORTD &= ~BIT(POLARITY);
65 if(packet.repeat_count>1)
67 if(packet.repeat_count<0xFF)
68 --packet.repeat_count;
69 delay_time = packet.repeat_delay;
74 delay_time = packet.final_delay;
81 out_data = packet.data[out_bit>>3];
86 PORTD |= BIT(POLARITY);
88 PORTD &= ~BIT(POLARITY);
90 out_time = packet.bit_duration;
96 if(packet.ready && !packet.sending)
100 out_time = packet.bit_duration;
101 out_data = packet.data[0];
103 PORTD |= BIT(POLARITY);
105 PORTD &= ~BIT(POLARITY);
109 TIMER_SET_CALLBACK(2, output_tick)