1 #ifndef MICROMAG_FW_HW_H
2 #define MICROMAG_FW_HW_H
13 #include "generated/airframe.h"
15 #define MM_DIVISOR_128 2
16 #define MM_DIVISOR_256 3
17 #define MM_DIVISOR_512 4
18 #define MM_DIVISOR_1024 5
20 #define MM_DIVISOR MM_DIVISOR_512
25 #define MmSelect() SetBit(MM_SS_IOCLR,MM_SS_PIN)
26 #define MmUnselect() SetBit(MM_SS_IOSET,MM_SS_PIN)
28 #define MmReset() SetBit(MM_RESET_IOCLR,MM_RESET_PIN)
29 #define MmSet() SetBit(MM_RESET_IOSET,MM_RESET_PIN)
31 #define MmOnSpiIt() { \
32 switch (micromag_status) { \
33 case MM_SENDING_REQ: \
36 uint8_t foo __attribute__ ((unused)) = SSPDR; \
37 micromag_status = MM_WAITING_EOC; \
44 case MM_READING_RES: \
47 new_val = SSPDR << 8; \
49 if (abs(new_val) < 2000) \
50 micromag_values[micromag_cur_axe] = new_val; \
56 if (micromag_cur_axe > 2) { \
57 micromag_cur_axe = 0; \
58 micromag_status = MM_DATA_AVAILABLE; \
61 micromag_status = MM_IDLE; \
68 #define MmSendReq() { \
70 micromag_status = MM_SENDING_REQ; \
75 uint8_t control_byte = (micromag_cur_axe+1) << 0 | MM_DIVISOR_1024 << 4; \
76 SSPDR = control_byte; \
80 #define MmReadRes() { \
81 micromag_status = MM_READING_RES; \
void micromag_hw_init(void)
Architecture independent SPI (Serial Peripheral Interface) API.
Arch independent mcu ( Micro Controller Unit ) utilities.
volatile uint8_t micromag_cur_axe