47 #define LIS3DH_CHIP_SELECT_PIN 0
63 spi_transfer(
const uint8_t data,
const bool cont,
const bool blocking)
67 spi_pushr = SPI_PUSHR_TXDATA(data);
68 spi_pushr |= SPI_PUSHR_CTAS(LIS3DH_CTAS);
69 spi_pushr |= SPI_PUSHR_PCS((1 << LIS3DH_CHIP_SELECT_PIN));
71 spi_pushr |= SPI_PUSHR_CONT_MASK;
75 SPI0->SR |= SPI_SR_TCF_MASK;
78 SPI0->PUSHR = spi_pushr;
82 while(!(
SPI0->SR & SPI_SR_TCF_MASK)) ;
86 return 0xFF &
SPI0->POPR;
97 MK60_ENTER_CRITICAL_REGION();
99 spi_transfer(value,
false,
true);
100 MK60_LEAVE_CRITICAL_REGION();
113 MK60_ENTER_CRITICAL_REGION();
115 data = spi_transfer(0,
false,
true);
116 MK60_LEAVE_CRITICAL_REGION();
131 MK60_ENTER_CRITICAL_REGION();
146 data = spi_transfer(0xFF,
true,
true);
147 data |= (spi_transfer(0xFF,
false,
true) << 8);
149 MK60_LEAVE_CRITICAL_REGION();
150 return (int16_t)data;
161 uint8_t *buffer, uint8_t count)
167 MK60_ENTER_CRITICAL_REGION();
180 *buffer = spi_transfer(0xFF,
true,
true);
185 *buffer = spi_transfer(0xFF,
false,
true);
187 MK60_LEAVE_CRITICAL_REGION();
198 const uint8_t *buffer, uint8_t count)
204 MK60_ENTER_CRITICAL_REGION();
217 spi_transfer(*buffer,
true,
true);
222 spi_transfer(*buffer,
false,
true);
224 MK60_LEAVE_CRITICAL_REGION();
234 SIM->SCGC5 |= SIM_SCGC5_PORTD_MASK;
238 SIM->SCGC6 |= SIM_SCGC6_SPI0_MASK;
244 SPI0->MCR = SPI_MCR_MSTR_MASK | SPI_MCR_PCSIS(0x1F) | SPI_MCR_DIS_RXF_MASK | SPI_MCR_DIS_TXF_MASK;
251 SPI0->CTAR[LIS3DH_CTAS] = SPI_CTAR_FMSZ(7) | SPI_CTAR_CSSCK(2) | SPI_CTAR_ASC(2) | SPI_CTAR_DT(2) | SPI_CTAR_BR(4) | SPI_CTAR_CPOL_MASK | SPI_CTAR_CPHA_MASK;
254 PORTD->PCR[0] = PORT_PCR_MUX(2);
255 PORTD->PCR[1] = PORT_PCR_MUX(2);
256 PORTD->PCR[2] = PORT_PCR_MUX(2);
257 PORTD->PCR[3] = PORT_PCR_MUX(2);
lis3dh_reg_addr_t
All LIS3DH hardware registers are enumerated here.
int16_t lis3dh_read_int16(const lis3dh_reg_addr_t lsb_addr)
Read a 16-bit integer from the LIS3DH.
#define LIS3DH_SPI_MULTI_MASK
Multi byte transfers must assert this bit when writing the address.
void lis3dh_memcpy_from_device(const lis3dh_reg_addr_t start_address, uint8_t *buffer, uint8_t count)
Read multiple bytes from the LIS3DH.
void lis3dh_memcpy_to_device(const lis3dh_reg_addr_t start_address, const uint8_t *buffer, uint8_t count)
Write multiple bytes to the LIS3DH.
#define LIS3DH_SPI_ADDRESS_MASK
Mask of the address bits in the address byte during transfers.
Power control pins for the on board power switches on the Mulle board.
void lis3dh_arch_init()
Perform the platform specific part of the initialization process of the LIS3DH.
#define SIM
Peripheral SIM base pointer.
#define SPI0
Peripheral SPI0 base pointer.
K60 hardware register header wrapper.
#define LIS3DH_SPI_SINGLE_MASK
Opposite of LIS3DH_SPI_MULTI_MASK.
Interface of LIS3DH SPI driver used in the Mulle platform.
#define LIS3DH_SPI_READ_MASK
The READ bit must be set when reading.
K60 interrupt save/restore macros.
#define PORTD
Peripheral PORTD base pointer.
void lis3dh_write_byte(const lis3dh_reg_addr_t addr, const uint8_t value)
Write a single byte to the LIS3DH.
uint8_t lis3dh_read_byte(const lis3dh_reg_addr_t addr)
Read a single byte from the LIS3DH.