Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
echavemann committed Dec 1, 2024
1 parent 39003e3 commit 462b6c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/hal/i2c_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <stdint.h>
#include "nrf_twi_mngr.h"

namespace edge::aidan {

static uint8_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr);

static void i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t data);

void lsm303agr_init(const nrf_twi_mngr_t* i2c);
} // namespace edge::aidan
37 changes: 37 additions & 0 deletions src/hal/i2c_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "hal/i2c_wrapper.hpp"
#include "cmsis_gcc.h"
#include "nrf_error.h"
#include "nrf_twi_mngr.h"
#include "sdk_errors.h"

namespace edge::aidan {

static const nrf_twi_mngr_t* i2c_manager = NULL;

uint8_t i2c_reg_read(uint8_t i2c_addr, uint8_t reg_addr)
{
uint8_t rx_buf = 0;
nrf_twi_mngr_transfer_t const read_transfer[] = {
NRF_TWI_MNGR_WRITE(i2c_addr, &reg_addr, 1, NRF_TWI_MNGR_NO_STOP),
NRF_TWI_MNGR_READ(i2c_addr, &rx_buf, 1, NRF_TWI_MNGR_NO_STOP)
};
ret_code_t result = nrf_twi_mngr_perform(i2c_manager, NULL, read_transfer, 2, NULL);
if (result != NRF_SUCCESS)
{
printf("I2C TRANSACTION FAILED!");
}
return rx_buf;
};

void i2c_reg_write(uint8_t i2c_addr, uint8_t reg_addr, uint8_t data)
{
return;
}

void lsm303agr_init(const int *i2c)
{
return;
}


}

0 comments on commit 462b6c3

Please sign in to comment.