You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.6 KiB

/*
"THE BEER/MATE-WARE LICENSE":
<xil@xil.se> wrote this file. As long as you retain this notice you
can do whatever you want with this stuff. If we meet some day, and you think
this stuff is worth it, you can buy us a ( > 0 ) beer/mate in return - The Xil TEAM
*/
#ifndef DRIVERS_H
#define DRIVERS_H
#include <stdint.h>
#include <stdbool.h>
// Forward declare driver_bus for the drivers
typedef union driver_bus_params driver_bus_params_t;
typedef struct driver_bus driver_bus_t;
typedef union driver_params driver_params_t;
typedef struct driver driver_t;
typedef bool (*driver_print_value)(char* data, uint16_t* index, int i, const char* string, void* value, int size);
typedef bool (*driver_print_string)(char* data, uint16_t* index, int i, const char* string, const char* value);
typedef struct {
char* data;
uint16_t* index;
int i;
driver_print_value print_value;
driver_print_string print_string;
} driver_print_data_t;
typedef bool (*driver_bus_init)(driver_bus_params_t* params);
typedef bool (*driver_bus_print)(driver_bus_params_t* params, driver_print_data_t* data);
typedef bool (*driver_sensor_init)(driver_params_t* params, driver_bus_t* bus);
typedef bool (*driver_sensor_read)(driver_params_t* params);
typedef bool (*driver_sensor_print)(driver_params_t* params, driver_print_data_t* data);
typedef struct driver_bus_type {
const driver_bus_init init;
const driver_bus_print print;
} driver_bus_type_t;
typedef struct driver_sensor {
const driver_sensor_init init;
const driver_sensor_read read;
const driver_sensor_print print;
} driver_sensor_t;
#include "drivers/i2c.h"
#include "drivers/bmp180.h"
#include "drivers/bmp280.h"
#include "drivers/tsl2561.h"
#include "drivers/htu21.h"
// Global, constant variables for function pointers
// Busses
extern const driver_bus_type_t bus_i2c;
// Sensors
extern const driver_sensor_t sensor_bmp180;
extern const driver_sensor_t sensor_bmp280;
extern const driver_sensor_t sensor_tsl2561;
extern const driver_sensor_t sensor_htu21;
// Data buses
union driver_bus_params {
i2c_t i2c;
// spi_data spi;
};
struct driver_bus {
driver_bus_params_t params;
const driver_bus_type_t* bus;
};
// Sensor drivers
union driver_params {
bmp180_t bmp180;
bmp280_t bmp280;
tsl2561_t tsl2561;
htu21_t htu21;
};
struct driver {
driver_bus_t* bus;
driver_params_t params;
const driver_sensor_t* sensor;
};
#endif // DRIVERS_H