template libraru
Diff: ADxxxx.cpp
- Revision:
- 1:9524c69f480d
- Parent:
- 0:ba4696a23d38
- Child:
- 2:1857aa1363ef
--- a/ADxxxx.cpp Mon Jul 08 21:56:23 2019 +0000 +++ b/ADxxxx.cpp Thu Jul 18 00:12:31 2019 +0000 @@ -0,0 +1,54 @@ +/******************************/ +/* C FILE TEMPLATE */ +/******************************/ +#include "mbed.h" /*Neccessary Include Files*/ +#include "ADxxxx.h" + +#define ADXXXX_POWER_FULL 3 +#define ADXXXX_POWER_MED 2 +#define ADXXXX_POWER_LOW 1 + +#define ADXXXX_CALIBRATED 1 +#define ADXXXX_NOT_CALIBRATED 0 +/*Actual Declaration of all registers + based on the four fields declared in + the header file + {Address, Value, Size, Read or Write}*/ +struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUMB] = { + {0x00, 0x00, 1, 1}, /* EX_ADXXXX_READ_WRITE_REG */ + {0x01, 0x00, 1, 2}, /* EX_ADXXXX_READ_REG */ + {0x02, 0x00, 1, 3}, /* EX_ADXXXX_WRITE_REG */ +}; + +/*Function to malloc space for descriptor as well + as start the proper serial communication + **You should only be using either SPI or I2C at once** + Parameters: Pointer to a pointer to the device descriptor + Return Value: SUCCESS, FAILURE (You can make these more appropriate return + values if you would like, making it more + readable)*/ +static int adxxxx_setup(struct adxxxx_descriptor **device, struct adxxxx_init_params init_param) { + + int8_t return_val = 1; + struct adxxxx_descriptor * desc; + extern struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUMB]; + + desc = (struct adxxxx_descriptor *)malloc(sizeof(*desc)); + if (!desc) + return FAILURE; + + desc->all_regs = adxxxx_all_regs; + + /*Example of turning the device on and calibrating + it, but clearly this is device specific*/ + desc->is_calibrated = 1; + desc->power_level = 1; + + //return_val = spi_init(&desc->spi_desc, &init_params.spi_init); + //return_val = i2c_init(&desc->i2c_desc, &init_params.i2c_init); + if (return_val < 1) + return FAILURE; + + *device = desc; + return SUCCESS; +} \ No newline at end of file