4 #include "ReadWriteBits.h"
10 typedef uint8_t
volatile *
const lis_ptr;
11 typedef uint8_t
const lis_pin;
12 typedef uint8_t
const lis_bit;
18 extern lis_ptr Lis_ddr1;
19 extern lis_ptr Lis_port1;
20 extern lis_ptr Lis_pin1;
21 extern lis_ptr Lis_ddr2;
22 extern lis_ptr Lis_port2;
23 extern lis_ptr Lis_TCCR0A;
24 extern lis_ptr Lis_TCCR0B;
25 extern lis_ptr Lis_TIFR0;
26 extern lis_ptr Lis_OCR0A;
27 extern lis_ptr Lis_OCR0B;
29 extern lis_pin Lis_PixSelect;
30 extern lis_pin Lis_Clk;
31 extern lis_pin Lis_Rst;
32 extern lis_pin Lis_Sync;
34 extern lis_bit Lis_WGM00;
35 extern lis_bit Lis_WGM01;
36 extern lis_bit Lis_WGM02;
37 extern lis_bit Lis_CS00;
38 extern lis_bit Lis_CS01;
39 extern lis_bit Lis_CS02;
40 extern lis_bit Lis_COM0B0;
41 extern lis_bit Lis_COM0B1;
42 extern lis_bit Lis_OCF0A;
43 extern lis_bit Lis_OCF0B;
45 inline void Pin_LisPixSelect_SetOutput(
void)
47 SetBit(Lis_ddr2, Lis_PixSelect);
51 inline void LisPixSelectIdleLow(
void)
53 ClearBit(Lis_port2, Lis_PixSelect);
57 inline void Pin_LisClk_SetOutput(
void)
59 SetBit(Lis_ddr1, Lis_Clk);
63 inline void Pin_LisRst_SetOutput(
void)
65 SetBit(Lis_ddr1, Lis_Rst);
69 inline void LisRstIdleLowAfterPowerUp(
void)
71 ClearBit(Lis_port1, Lis_Rst);
75 inline void Pin_LisSync_SetInput(
void)
77 ClearBit(Lis_ddr1, Lis_Sync);
81 inline void ResetPwmTimerAtTop(
void)
83 SetBit(Lis_TCCR0A, Lis_WGM00);
84 SetBit(Lis_TCCR0A, Lis_WGM01);
94 inline void PwmTimerTopIsOCR0A(
void)
96 SetBit(Lis_TCCR0B, Lis_WGM02);
102 inline void PwmTimerClockedByCpu_NoPrescaling(
void)
104 SetBit(Lis_TCCR0B, Lis_CS00);
105 ClearBit(Lis_TCCR0B, Lis_CS01);
106 ClearBit(Lis_TCCR0B, Lis_CS02);
121 ResetPwmTimerAtTop();
122 PwmTimerTopIsOCR0A();
123 PwmTimerClockedByCpu_NoPrescaling();
142 ClearBit(Lis_TCCR0A, Lis_COM0B0);
143 SetBit(Lis_TCCR0A, Lis_COM0B1);
191 config[0]=0x00; config[1]=0x00; config[2]=0x00; config[3]=0x00;
194 if (BINNING_ON == binning) config[0] |= 1<<(bit++);
199 if (GAIN_2X5 == gain) { bit++; config[0] |= 1<<(bit++); }
200 else if (GAIN_4X == gain) { config[0] |= 1<<(bit++); bit++; }
201 else if (GAIN_5X == gain) { config[0] |= 1<<(bit++); config[0] |= 1<<(bit++); }
202 else { bit++; bit++; }
213 uint8_t
const row1 = 0; uint8_t
const row1_mask[] = {0x00,0x84,0x21,0x08};
214 uint8_t
const row2 = 1; uint8_t
const row2_mask[] = {0x01,0x08,0x42,0x10};
215 uint8_t
const row3 = 2; uint8_t
const row3_mask[] = {0x02,0x10,0x84,0x20};
216 uint8_t
const row4 = 3; uint8_t
const row4_mask[] = {0x04,0x21,0x08,0x40};
217 uint8_t
const row5 = 4; uint8_t
const row5_mask[] = {0x08,0x42,0x10,0x80};
221 if (active_rows&(1<<row1))
223 config[0] |= row1_mask[3];
224 config[1] |= row1_mask[2];
225 config[2] |= row1_mask[1];
226 config[3] |= row1_mask[0];
228 if (active_rows&(1<<row2))
230 config[0] |= row2_mask[3];
231 config[1] |= row2_mask[2];
232 config[2] |= row2_mask[1];
233 config[3] |= row2_mask[0];
235 if (active_rows&(1<<row3))
237 config[0] |= row3_mask[3];
238 config[1] |= row3_mask[2];
239 config[2] |= row3_mask[1];
240 config[3] |= row3_mask[0];
242 if (active_rows&(1<<row4))
244 config[0] |= row4_mask[3];
245 config[1] |= row4_mask[2];
246 config[2] |= row4_mask[1];
247 config[3] |= row4_mask[0];
249 if (active_rows&(1<<row5))
251 config[0] |= row5_mask[3];
252 config[1] |= row5_mask[2];
253 config[2] |= row5_mask[1];
254 config[3] |= row5_mask[0];
264 SetBit(Lis_TIFR0, Lis_OCF0B);
266 while(BitIsClear(Lis_TIFR0, Lis_OCF0B));
275 SetBit(Lis_TIFR0, Lis_OCF0A);
277 while(BitIsClear(Lis_TIFR0, Lis_OCF0A));
281 #define _WaitForLisClkLow _WaitForLisClkLow_fake
296 SetBit(Lis_port2, Lis_PixSelect);
301 #undef _WaitForLisClkLow
312 ClearBit(Lis_port1, Lis_Rst);
315 ClearBit(Lis_port2, Lis_PixSelect);
321 #define _WaitForLisClkLow _WaitForLisClkLow_fake
322 #define _WaitForLisClkHigh _WaitForLisClkHigh_fake
344 BitIsSet((uint8_t *)config, bit_index) ?
345 SetBit(Lis_port1, Lis_Rst)
347 ClearBit(Lis_port1, Lis_Rst);
353 #undef _WaitForLisClkLow
354 #undef _WaitForLisClkHigh
358 #define _WriteLisConfigBit _WriteLisConfigBit_fake
366 for (uint8_t cfg_byte_i = 0; cfg_byte_i < 3; cfg_byte_i++)
368 for (uint8_t bit_i = 0; bit_i<8; bit_i++)
379 #undef _WriteLisConfigBit
400 #define MAX_NUM_PIXELS 784
401 inline uint8_t
MSB(uint16_t msb_lsb)
408 inline uint8_t
LSB(uint16_t msb_lsb)
413 return msb_lsb & 0xFF;
432 Pin_LisPixSelect_SetOutput();
433 LisPixSelectIdleLow();
434 Pin_LisClk_SetOutput();
435 Pin_LisRst_SetOutput();
436 LisRstIdleLowAfterPowerUp();
437 Pin_LisSync_SetInput();
454 (binning == BINNING_OFF) || (binning == BINNING_ON)
459 (gain == GAIN_2X5) ||
465 (active_rows & 0xE0) == 0x00
470 #define _ConfigAs28bits _ConfigAs28bits_fake
471 #define _EnterLisProgrammingMode _EnterLisProgrammingMode_fake
472 #define _Write28bitLisConfig _Write28bitLisConfig_fake
473 #define _ExitLisProgrammingMode _ExitLisProgrammingMode_fake
492 #undef _ConfigAs28bits
493 #undef _EnterLisProgrammingMode
494 #undef _Write28bitLisConfig
495 #undef _ExitLisProgrammingMode
510 SetBit(Lis_port1, Lis_Rst);
513 uint16_t tick_count = 0;
521 ClearBit(Lis_port1, Lis_Rst);
bool LisConfigIsValid(uint8_t binning, uint8_t gain, uint8_t active_rows)
void _ExitLisProgrammingMode(void)
uint8_t MSB(uint16_t msb_lsb)
void _ConfigAs28bits(uint8_t *config)
void _EnterLisProgrammingMode(void)
void _WaitForLisClkHigh(void)
void _WriteLisConfigBit(uint8_t const *config, uint8_t bit_index)
void LisWriteConfig(void)
uint16_t exposure_ticks
LIS-770i exposure time.
void LisClkFreq50kHz(void)
void _WaitForLisClkLow(void)
void _Write28bitLisConfig(uint8_t const *config)
uint8_t LSB(uint16_t msb_lsb)