Skip to content

Commit

Permalink
Updated interface design and examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
BST-Github-Admin authored and kegov committed Jul 6, 2020
1 parent 94f5531 commit c47f06e
Show file tree
Hide file tree
Showing 7 changed files with 871 additions and 388 deletions.
10 changes: 5 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ struct bme280_dev dev;
int8_t rslt = BME280_OK;

/* Sensor_0 interface over SPI with native chip select line */
dev.dev_id = 0;
uint8_t dev_addr = 0;

dev.intf_ptr = &dev_addr;
dev.intf = BME280_SPI_INTF;
dev.read = user_spi_read;
dev.write = user_spi_write;
Expand All @@ -46,8 +48,9 @@ rslt = bme280_init(&dev);
``` c
struct bme280_dev dev;
int8_t rslt = BME280_OK;
uint8_t dev_addr = BME280_I2C_ADDR_PRIM;

dev.dev_id = BME280_I2C_ADDR_PRIM;
dev.intf_ptr = &dev_addr;
dev.intf = BME280_I2C_INTF;
dev.read = user_i2c_read;
dev.write = user_i2c_write;
Expand Down Expand Up @@ -119,7 +122,7 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev)
while (1) {
rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev);
/* Wait for the measurement to complete and print data @25Hz */
dev->delay_ms(req_delay);
dev->delay_ms(req_delay, dev->intf_ptr);
rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
print_sensor_data(&comp_data);
}
Expand Down Expand Up @@ -161,7 +164,7 @@ int8_t stream_sensor_data_normal_mode(struct bme280_dev *dev)
printf("Temperature, Pressure, Humidity\r\n");
while (1) {
/* Delay while the sensor completes a measurement */
dev->delay_ms(70);
dev->delay_ms(70, dev->intf_ptr);
rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev);
print_sensor_data(&comp_data);
}
Expand All @@ -182,20 +185,20 @@ void print_sensor_data(struct bme280_data *comp_data)
### Templates for function pointers
``` c

void user_delay_ms(uint32_t period)
void user_delay_ms(uint32_t period, void *intf_ptr)
{
/*
* Return control or wait,
* for a period amount of milliseconds
*/
}

int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
int8_t user_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

/*
* The parameter dev_id can be used as a variable to select which Chip Select pin has
* The parameter intf_ptr can be used as a variable to select which Chip Select pin has
* to be set low to activate the relevant device on the SPI bus
*/

Expand All @@ -216,12 +219,12 @@ int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16
return rslt;
}

int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
int8_t user_spi_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

/*
* The parameter dev_id can be used as a variable to select which Chip Select pin has
* The parameter intf_ptr can be used as a variable to select which Chip Select pin has
* to be set low to activate the relevant device on the SPI bus
*/

Expand All @@ -242,12 +245,12 @@ int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint1
return rslt;
}

int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
int8_t user_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

/*
* The parameter dev_id can be used as a variable to store the I2C address of the device
* The parameter intf_ptr can be used as a variable to store the I2C address of the device
*/

/*
Expand All @@ -269,12 +272,12 @@ int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16
return rslt;
}

int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
int8_t user_i2c_write(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */

/*
* The parameter dev_id can be used as a variable to store the I2C address of the device
* The parameter intf_ptr can be used as a variable to store the I2C address of the device
*/

/*
Expand Down
Loading

0 comments on commit c47f06e

Please sign in to comment.