39 #include "SpiSlave_faked.h"
40 #include "UartSpi_faked.h"
47 #include <util/delay_basic.h>
51 #define WaitForS13131ClkLow WaitForS13131ClkLow_fake
52 #define StartAdcConversion StartAdcConversion_fake
58 extern uint8_t
frame[];
71 return ( (led_num == 0) || (led_num == 1) );
83 if (BitIsClear(BiColorLed_ddr, led_num))
86 return BitIsClear(BiColorLed_port, led_num)
90 inline bool AutoExposeConfigIsValid(
91 uint8_t new_max_tries,
92 uint16_t new_start_pixel,
93 uint16_t new_stop_pixel,
98 if (new_max_tries == 0)
return false;
101 if (new_target < 4500)
return false;
104 if (new_stop_pixel < new_start_pixel)
return false;
108 if (binning == BINNING_ON)
110 if ((new_start_pixel < 7) || (new_start_pixel > 392))
return false;
111 if ((new_stop_pixel < 7) || (new_stop_pixel > 392))
return false;
115 if ((new_start_pixel < 14) || (new_start_pixel > 784))
return false;
116 if ((new_stop_pixel < 14) || (new_stop_pixel > 784))
return false;
120 if ((new_start_pixel < 1) || (new_start_pixel > 512))
return false;
121 if ((new_stop_pixel < 1) || (new_stop_pixel > 512))
return false;
130 static inline void LisReadout(uint16_t num_pixels)
146 while( BitIsClear(Lis_pin1, Lis_Sync) );
147 while( BitIsSet(Lis_pin1, Lis_Sync) );
152 uint16_t pixel_count = 0;
153 uint8_t *pframe =
frame;
154 while( pixel_count++ < num_pixels)
160 StartAdcConversion();
175 while (BitIsClear(UartSpi_UCSR0A, UartSpi_RXC0));
178 *(pframe++) = *UartSpi_UDR0;
181 while (BitIsClear(UartSpi_UCSR0A, UartSpi_RXC0));
184 *(pframe++) = *UartSpi_UDR0;
190 static inline void S13131Readout(
void)
214 uint8_t *pframe =
frame;
231 for(uint16_t p_count = 0; p_count < 512; p_count++)
233 WaitForS13131ClkLow();
236 StartAdcConversion();
251 while (BitIsClear(UartSpi_UCSR0A, UartSpi_RXC0));
254 *(pframe++) = *UartSpi_UDR0;
257 while (BitIsClear(UartSpi_UCSR0A, UartSpi_RXC0));
260 *(pframe++) = *UartSpi_UDR0;
265 uint16_t
GetPeak(uint16_t
const, uint16_t
const);
345 case 0: led = led_0;
break;
346 case 1: led = led_1;
break;
461 LisReadout(num_pixels);
478 uint8_t *pframe =
frame;
480 uint16_t byte_count = 0;
481 uint16_t nbytes = 2*num_pixels;
482 while( byte_count++ < nbytes )
499 inline void AutoExposure(
void)
513 inline void GetAutoExposeConfig(
void)
529 inline void SetAutoExposeConfig(
void)
541 uint8_t msb; uint8_t lsb;
548 uint16_t new_start_pixel = (uint16_t)(msb << 8) | lsb;
555 uint16_t new_stop_pixel = (uint16_t)(msb << 8) | lsb;
562 uint16_t new_target = (uint16_t)(msb << 8) | lsb;
569 uint16_t new_target_tolerance = (uint16_t)(msb << 8) | lsb;
576 uint16_t new_max_exposure = (uint16_t)(msb << 8) | lsb;
583 if ( !AutoExposeConfigIsValid(
585 new_start_pixel, new_stop_pixel,
613 #define SpiSlaveTxByte SpiSlaveTxByte_fake
614 #define LisWriteConfig LisWriteConfig_fake
648 binning = new_binning;
650 active_rows = new_active_rows;
657 #undef SpiSlaveTxByte
658 #undef LisWriteConfig
666 #define SpiSlaveTxByte SpiSlaveTxByte_fake
672 #define SENSOR S13131
674 inline void GetSensorHash(
void)
677 uint8_t first_byte = SENSOR >> 16;
678 uint8_t second_byte = (SENSOR >> 8) & 0xff;
679 uint8_t third_byte = SENSOR & 0xff;
685 #undef SpiSlaveTxByte
uint16_t max_exposure
max_exposure is 1.31 seconds (65535 20µs-cycles) This is the 16-bit limit, UINT16_MAX,...
uint16_t start_pixel
AutoExpose() ignores pixels below start_pixel.
uint8_t max_tries
maximum number of tries before AutoExpose() gives up
uint16_t stop_pixel
AutoExpose() ignores pixels above stop_pixel.
uint16_t target_tolerance
target ± target_tolerance is the target peak counts range for AutoExpose().
uint16_t target
target peak counts for AutoExpose().
void BiColorLedOff(bicolorled_num led)
void BiColorLedGreen(bicolorled_num led)
void BiColorLedRed(bicolorled_num led)
void BiColorLedOn(bicolorled_num led)
uint8_t const bicolorled_num
Indicator LED numbers in the JSON file are not necessarily the same as the corresponding bit number i...
bool LisConfigIsValid(uint8_t binning, uint8_t gain, uint8_t active_rows)
uint8_t MSB(uint16_t msb_lsb)
void _WaitForLisClkHigh(void)
void LisWriteConfig(void)
uint16_t exposure_ticks
LIS-770i exposure time.
uint8_t LSB(uint16_t msb_lsb)
#define MAX_NUM_PIXELS
LIS-770i maximum number of pixels.
uint8_t QueuePop(volatile Queue_s *SpiFifo)
bool QueueIsEmpty(volatile Queue_s *SpiFifo)
spi_ptr Spi_SPDR
SPI Data Register.
void _SignalDataNotReady(void)
void EnableSpiInterrupt(void)
void DisableSpiInterrupt(void)
void SpiSlaveTxByte(uint8_t input_byte)
void _SignalDataReady(void)
bool _SpiTransferIsDone(void)
See cfg/microspec.json in the Python API repository.
bool led_setting_is_valid(led_state setting)
uint8_t PADDING
When status_code is ERROR, pad responses to send expected number of bytes.
void GetSensorConfig(void)
void SetSensorConfig(void)
uint8_t frame[]
One frame of pixel data is, at most, 1568 bytes.
volatile Queue_s * SpiFifo
Allocate static memory for the SPI Rx Queue.
uint8_t ReadLedState(bicolorled_num led_num)
uint16_t GetPeak(uint16_t const, uint16_t const)
bool LedNumIsValid(bicolorled_num led_num)
uint16_t AutoExpose(void)
static void CaptureFrame(void)
Queue uses a byte array as a circular buffer.