template libraru

Revision:
2:1857aa1363ef
Parent:
1:9524c69f480d
Child:
3:ecb47ce6f212
--- a/ADxxxx.cpp	Thu Jul 18 00:12:31 2019 +0000
+++ b/ADxxxx.cpp	Fri Jul 19 00:12:11 2019 +0000
@@ -4,20 +4,14 @@
 #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 */        
+struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUM] = {
+    {0x00, 0x00,   1, 1}, /*EX_ADXXXX_POWER_ON*/
+    {0x01, 0x00,   1, 1}, /*EX_ADXXXX_POWER_LEVEL*/    
+    {0x02, 0x00,   1, 1}, /*EX_ADXXXX_CALIBRATION*/        
 };
 
 /*Function to malloc space for descriptor as well
@@ -27,11 +21,11 @@
   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) {
+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];
+    extern struct adxxxx_reg adxxxx_all_regs[ADXXXX_REG_NUM];
     
     desc = (struct adxxxx_descriptor *)malloc(sizeof(*desc));
     if (!desc) 
@@ -41,9 +35,10 @@
     
     /*Example of turning the device on and calibrating
       it, but clearly this is device specific*/
-    desc->is_calibrated = 1;
-    desc->power_level = 1;
+    desc->is_calibrated = ADXXXX_NOT_CALIBRATED;
+    desc->power_level = ADXXXX_POW_IDLE;
     
+    /*Uncomment the protocol your device uses*/
     //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) 
@@ -51,4 +46,41 @@
     
     *device = desc;
     return SUCCESS;     
+}
+
+/*Function to sweep through all of the registers and set them
+  to their initial values
+  Parameters: Pointer to adxxxx's descriptor
+  Return Value: SUCCESS, FAILURE*/
+int adxxxx_init_regs(struct adxxxx_descriptor *device) {
+    /*Sweep through all of the registers that you initialized
+      in the struct above and write all the values to the device
+      (Could return register that failed to be written to may be
+      helpful for debugging)*/
+    return SUCCESS;    
+}
+
+/*Function to make a single or multi read from the device, based off 
+  the registers size which you can find in the devices data sheet
+  Parameters: Pointer to adxxxx's descriptor, register struct to read from
+  Return Value: SUCCESS, FAILURE*/
+int adxxx_read(struct adxxxx_descriptor *device, struct adxxxx_reg* reg) {
+    /*Follow your devices specific write protocol (I2C, SPI) in conjunction 
+      with the platform specific drivers to effectively communicate with your
+      device (A good first step is perhaps reading your devices ID register
+      or something else that is easy to get to)*/
+    return SUCCESS;        
+}
+
+/*Function to make a single or multi write to the device, based off 
+  the registers size which you can find in the devices data sheet
+  Parameters: Pointer to adxxxx's descriptor, register struct to read from
+  Return Value: SUCCESS, FAILURE*/
+int adxxx_write(struct adxxxx_descriptor *device, struct adxxxx_reg* reg, uint32_t data) {
+    /*Follow your devices specific write protocol (I2C, SPI) in conjunction 
+      with the platform specific drivers to effectively communicate with your
+      device (Try and write to a read-enabled register and then immediately
+      read back the value you wrote)*/
+    reg->value = data;
+    return SUCCESS;    
 }
\ No newline at end of file