3 pinOutput( CC_CS_DDR, CC_CS_PIN );
4 pinOutput( SPI_DDR, SPI_MOSI );
5 pinInput ( SPI_DDR, SPI_MISO );
6 pinOutput( SPI_DDR, SPI_SCLK );
7 pinInput ( CC_GDO0_DDR, CC_GDO0_PIN );
9 SPCR = _BV(SPE) | _BV(MSTR);
11 CC_GDO0_PCICR |= _BV(CC_GDO0_PCIE);
13 uint8_t ccSendByte(uint8_t data) {
15 while (!(SPSR & _BV(SPIF)));
19 uint8_t x = chkPCINT(CC_GDO0_PCIE, CC_GDO0_INT);
22 if (x == 2 )
return 1;
26 void enableGDO0Int(
void) {
28 CC_GDO0_PCMSK |= _BV(CC_GDO0_INT);
30 void disableGDO0Int(
void) {
32 CC_GDO0_PCMSK &= ~_BV(CC_GDO0_INT);
36 while(SPI_PORT & _BV(SPI_MISO));
39 setPinLow( CC_CS_PORT, CC_CS_PIN);
41 void ccDeselect(
void) {
42 setPinHigh( CC_CS_PORT, CC_CS_PIN);
49 pinOutput(LED_RED_DDR, LED_RED_PIN);
50 pinOutput(LED_GRN_DDR, LED_GRN_PIN);
52 setPinHigh(LED_RED_PORT, LED_RED_PIN);
53 setPinHigh(LED_GRN_PORT, LED_GRN_PIN);
56 void ledRed(uint8_t stat) {
57 stat ^= LED_ACTIVE_LOW;
58 if (stat == 1) setPinHigh(LED_RED_PORT, LED_RED_PIN);
59 else if (stat == 0) setPinLow(LED_RED_PORT, LED_RED_PIN);
60 else setPinCng(LED_RED_PORT, LED_RED_PIN);
62 void ledGrn(uint8_t stat) {
63 stat ^= LED_ACTIVE_LOW;
64 if (stat == 1) setPinHigh(LED_GRN_PORT, LED_GRN_PIN);
65 else if (stat == 0) setPinLow(LED_GRN_PORT, LED_GRN_PIN);
66 else setPinCng(LED_GRN_PORT, LED_GRN_PIN);
75 }
static volatile pcInt[3];
79 void initPCINT(
void) {
80 memset((uint8_t*)pcInt, 0x00,
sizeof(pcInt));
83 uint8_t chkPCINT(uint8_t port, uint8_t pin) {
86 uint8_t cur = pcInt[port].cur & _BV(pin);
87 uint8_t prev = pcInt[port].prev & _BV(pin);
89 if ((cur == prev) || ( (getMillis() - pcInt[port].time) < DEBOUNCE )) {
90 return (pcInt[port].cur & _BV(pin))?1:0;
100 pcInt[port].prev |= _BV(pin);
105 pcInt[port].prev &= ~_BV(pin);
119 void initConfKey(
void) {
121 pinInput(CONFIG_KEY_DDR, CONFIG_KEY_PIN);
122 setPinHigh(CONFIG_KEY_PORT,CONFIG_KEY_PIN);
125 regPCIE(CONFIG_KEY_PCIE);
126 regPCINT(CONFIG_KEY_PCMSK, CONFIG_KEY_INT);
138 pcInt[0].prev = pcInt[0].cur;
140 pcInt[0].time = getMillis();
144 pcInt[1].prev = pcInt[1].cur;
146 pcInt[1].time = getMillis();
150 pcInt[2].prev = pcInt[2].cur;
152 pcInt[2].time = getMillis();
161 void initExtBattMeasurement(
void);
162 void switchExtBattMeasurement(uint8_t stat);
167 uint8_t getBatteryVoltage(
void) {
168 #if defined EXT_BATTERY_MEASUREMENT
169 initExtBattMeasurement();
170 switchExtBattMeasurement(1);
173 #if defined EXT_BATTERY_MEASUREMENT
174 uint16_t adcValue = getAdcValue(
175 (1 << REFS1) | (1 << REFS0) | BATT_MEASURE_PIN
178 adcValue = adcValue * AVR_BANDGAP_VOLTAGE / 1023 / BATTERY_FACTOR;
179 switchExtBattMeasurement(0);
181 uint16_t adcValue = getAdcValue(
182 (0 << REFS1) | (1 << REFS0) | (1 << MUX3) | (1 << MUX2) | (1 << MUX1) | (0 << MUX0)
185 adcValue = AVR_BANDGAP_VOLTAGE * 1023 / adcValue / 100;
188 return (uint8_t)adcValue;
194 void initExtBattMeasurement(
void) {
195 pinInput(BATT_MEASURE_DDR, BATT_MEASURE_PIN);
196 pinInput(BATT_ENABLE_DDR, BATT_ENABLE_PIN);
203 void switchExtBattMeasurement(uint8_t stat) {
205 pinOutput(BATT_ENABLE_DDR, BATT_ENABLE_PIN);
206 setPinLow(BATT_ENABLE_PORT, BATT_ENABLE_PIN);
207 setPinLow(BATT_MEASURE_PORT, BATT_MEASURE_PIN);
209 pinInput(BATT_ENABLE_DDR, BATT_ENABLE_PIN);
212 setPinHigh(BATT_MEASURE_PORT, BATT_MEASURE_PIN);
Definition: HAL_extern.h:71