27 #if defined(BOARD_ATTINYX5) || defined(BOARD_ATTINYX61) 28 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384
30 0, 1, 8, 64, 256, 1024
46 uint16_t max_ticks = (1 << bits) - 1;
48 for (uint8_t i =
membersof(prescale) - 1; i > 0; i--) {
49 uint16_t scale = (uint16_t) pgm_read_word(&prescale[i]);
50 uint16_t count = (F_CPU / scale) / speed;
51 if (count > res && count < max_ticks) {
60 uint16_t start_symbol,
61 uint8_t preamble_max) :
62 BITS_PER_SYMBOL(bits_per_symbol),
63 START_SYMBOL(start_symbol),
64 PREAMBLE_MAX(preamble_max),
65 SYMBOL_MASK((1 << bits_per_symbol) - 1),
66 BITS_MSB(1 << (bits_per_symbol*2 - 1))
87 #if defined(BOARD_ATTINYX5) 90 if (!prescaler)
return (
false);
93 TCCR1 = _BV(PWM1A) | prescaler;
96 OCR1A = uint8_t(nticks);
97 #elif defined(BOARD_ATTINYX61) 99 prescaler =
timer_setting(m_speed * SAMPLES_PER_BIT, 8, &nticks);
100 if (!prescaler)
return (
false);
107 OCR1A = uint8_t(nticks);
110 prescaler =
timer_setting(m_speed * SAMPLES_PER_BIT, 16, &nticks);
111 if (!prescaler)
return (
false);
115 TCCR1B = _BV(WGM12) | prescaler;
138 if (m_rx !=
NULL) m_rx->begin();
146 while (m_tx->is_active())
yield();
149 if (m_rx !=
NULL) m_rx->end();
157 bool transmitting = (transmitter !=
NULL) && (transmitter->m_enabled);
158 bool receiving = (receiver !=
NULL) && (receiver->m_enabled);
161 if (!transmitting && receiving)
162 receiver->m_sample = receiver->
read();
166 if (transmitting && transmitter->m_sample++ == 0) {
169 if (transmitter->m_index >= transmitter->m_length) {
173 transmitter->
write(transmitter->m_buffer[transmitter->m_index] &
174 (1 << transmitter->m_bit++));
176 transmitter->m_bit = 0;
177 transmitter->m_index++;
182 transmitter->m_sample = 0;
185 if (!transmitting && receiving)
static uint8_t timer_setting(uint16_t speed, uint8_t bits, uint16_t *nticks)
static void timer1_disable()
static const uint8_t SAMPLES_PER_BIT
const uint8_t BITS_PER_SYMBOL
virtual bool begin(const void *config=NULL)
static const uint16_t prescale[] __PROGMEM
void write(int value) const
friend void TIMER1_COMPA_vect(void)
Codec(uint8_t bits_per_symbol, uint16_t start_symbol, uint8_t preamble_max=VWI::Transmitter::PREAMBLE_MAX)
static void timer1_enable()