27#include <avr/interrupt.h>
29#include <util/atomic.h>
31#define F_CPU 16000000L
33#define MYUBRR (F_CPU / 16 / BAUD - 1)
36bool have_started_ADC_conversion =
false;
37#define have_finished_ADC_conversion (!(ADCSRA & (1 << ADSC)))
40uint32_t adc_sample_period_ms = 1000;
75 &((uint8_t *)(&adc_sample_period_ms))[0],
76 &((uint8_t *)(&adc_sample_period_ms))[1],
77 &((uint8_t *)(&adc_sample_period_ms))[2],
78 &((uint8_t *)(&adc_sample_period_ms))[3],
142 Catch(e) {
return e; }
150 const bool stream_state_before_receiving = streaming_is_on;
153 if (streaming_is_on && !stream_state_before_receiving) {
155 adc_sample_period_ms);
158 if (streaming_is_on && !have_started_ADC_conversion &&
161 have_started_ADC_conversion =
true;
163 if (have_started_ADC_conversion && have_finished_ADC_conversion &&
165 const uint16_t adc_val = ADC;
166 char adc_val_buffer[4];
169 have_started_ADC_conversion =
false;
172 Catch(e) { nExceptions++; }
REGTYPE register_write_masks[nRegs]
Write masks for register_map.
volatile REGTYPE * register_map[nRegs]
Register Map.
#define HANDLE_ASC_COMM_IN_POLLING_LOOP(uart_no)
Polling for ascii_serial_com_device and ascii_serial_com_register_pointers.
#define STREAM_TO_HOST_ASC_DEVICE_W_REGISTER_POINTERS(data, data_size)
Stream data to the host.
#define READY_TO_STREAM_ASC_DEVICE_W_REGISTER_POINTERS
Check if you should stream a message to the host.
#define DECLARE_ASC_DEVICE_W_REGISTER_POINTERS()
Declarations for ascii_serial_com_device and ascii_serial_com_register_pointers.
#define SETUP_ASC_DEVICE_W_REGISTER_POINTERS(register_map, register_write_masks, nRegs)
Setup for ascii_serial_com_device and ascii_serial_com_register_pointers.
void convert_uint16_to_hex(uint16_t num, char *outstr, bool caps)
convert uint16 to hex string
ASCII Serial Com Register Pointers.
#define UART_Init(uart_no, ubrr, rxIntEnable)
Initialize USART.
void millisec_timer_set_rel(millisec_timer *timer, const millisec_timer_unit_t now, const millisec_timer_unit_t rel)
Set timer to expire in the future.
bool millisec_timer_is_expired_repeat(millisec_timer *timer, const millisec_timer_unit_t now)
Check if timer has expired & if so, re-enable for the same interval.
Portable millisecond timer.
static uint32_t MILLISEC_TIMER_NOW
A counter that increments every millisecond.
#define MILLISEC_TIMER_AVR_TIMER0_ISR
Millisecond timer SysTick interrupt.
#define millisec_timer_avr_timer0_setup_16MHz()
Setup the systick timer.
#define def_usart_isr_push_rx_to_circ_buf(isr_name, usart, circular_buffer)
Define the ISR for a USART to push rx bytes to a circular buffer.
portable millisecond timer