static uint8_t read_fom_reg(uint8_t addr) { AccSelect(); SPI_I2S_SendData(SPI2, (1<<7|addr)); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); uint8_t ret = SPI_I2S_ReceiveData(SPI2); AccUnselect(); return ret; }
static void write_to_reg(uint8_t addr, uint8_t val) { AccSelect(); SPI_I2S_SendData(SPI2, addr); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, val); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); AccUnselect(); }
static void write_to_reg(uint8_t addr, uint8_t val) { #warning "Needs porting to libopencm3 or use the real driver!" #if 0 AccSelect(); SPI_I2S_SendData(SPI2, addr); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, val); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); AccUnselect(); #endif }
static uint8_t read_fom_reg(uint8_t addr) { #warning "Needs porting to libopencm3 or use the real driver!" #if 0 AccSelect(); SPI_I2S_SendData(SPI2, (1<<7|addr)); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); uint8_t ret = SPI_I2S_ReceiveData(SPI2); AccUnselect(); #endif return ret; }
static void read_data(void) { #warning "Needs porting to libopencm3 or use the real driver!" #if 0 AccSelect(); SPI_I2S_SendData(SPI2, (1<<7|1<<6|ADXL345_REG_DATA_X0)); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); uint8_t __attribute__ ((unused)) foo = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[0] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[1] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[2] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[3] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[4] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[5] = SPI_I2S_ReceiveData(SPI2); AccUnselect(); #endif }
static void read_data(void) { AccSelect(); SPI_I2S_SendData(SPI2, (1<<7|1<<6|ADXL345_REG_DATA_X0)); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); uint8_t __attribute__ ((unused)) foo = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[0] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[1] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[2] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[3] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[4] = SPI_I2S_ReceiveData(SPI2); SPI_I2S_SendData(SPI2, 0x00); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET); while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_BSY) == SET); values[5] = SPI_I2S_ReceiveData(SPI2); AccUnselect(); }