Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete SPI API, added display ILI9341, added spi bme280, updated i2c bme280 #116

Merged
merged 83 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
c0d42b9
Add files via upload
enelson1001 Nov 8, 2019
0d76df2
Add files via upload
enelson1001 Nov 8, 2019
ede00ef
Add files via upload
enelson1001 Nov 8, 2019
3c424e3
Add files via upload
enelson1001 Nov 8, 2019
a0c31e2
Add files via upload
enelson1001 Nov 8, 2019
d1dc441
Add files via upload
enelson1001 Nov 8, 2019
65de6e1
Add files via upload
enelson1001 Nov 8, 2019
7471db6
Add files via upload
enelson1001 Nov 8, 2019
b65e46b
Add files via upload
enelson1001 Nov 8, 2019
b401bc2
Add files via upload
enelson1001 Nov 8, 2019
dd86b95
ili9341.h and ili9341_init_cmds.h
enelson1001 Nov 8, 2019
e8a9f33
Delete ILI9341.cpp
enelson1001 Nov 8, 2019
98d3d78
Delete BME280.cpp
enelson1001 Nov 8, 2019
45468b1
added new bme280.h
enelson1001 Nov 8, 2019
04f4432
Delete BME280Core.cpp
enelson1001 Nov 8, 2019
ba85948
Delete BME280SPI.cpp
enelson1001 Nov 8, 2019
bd2e4aa
added bme280spi.h and bme280Core.h
enelson1001 Nov 8, 2019
15feea2
Updated tag and res
enelson1001 Nov 9, 2019
9ed9ebd
updated tag, converted alignas to static_assert
enelson1001 Nov 9, 2019
6ea8ece
put && at the front
enelson1001 Nov 9, 2019
b1a1a8a
Updated special notes with GPIO_NUM_NC
enelson1001 Nov 9, 2019
5e5ff0c
Used GPIO_NUM_NC, updated tag
enelson1001 Nov 9, 2019
09cb262
commented out static_assert can't use on variable
enelson1001 Nov 9, 2019
5fbeb2e
Merge branch 'master' into master
PerMalmberg Nov 9, 2019
2721689
added ili9341 datasheet
enelson1001 Nov 12, 2019
67d37d4
updated to use DmaFixedBuffer
enelson1001 Nov 12, 2019
8fe30be
Updated to use DmaFixedBuffer
enelson1001 Nov 12, 2019
4fcc088
added DmaFixedBuffer
enelson1001 Nov 12, 2019
43793b6
minor comment changes
enelson1001 Nov 12, 2019
4f1778b
used DmaFixedBuffer
enelson1001 Nov 12, 2019
b1c7314
Added MallocCapType to constructor
enelson1001 Nov 14, 2019
997e39f
Removed static_assert user of class will do this
enelson1001 Nov 14, 2019
b0afc25
Removed special note at top
enelson1001 Nov 14, 2019
166623e
Moved malloc_cap_type to constructor
enelson1001 Nov 14, 2019
f012911
Added SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
2fa73fb
Moved comment from header file to here
enelson1001 Nov 17, 2019
82c314a
Moved comment to cpp file
enelson1001 Nov 17, 2019
e71e589
Removed cont_cast, Use SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
5c58e9e
Removed cont_cast, Used SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
42924ae
Removed cont_cast, Used SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
f04e6b4
Removed cont_cast, Used SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
6d80baf
Added SpiDmaFixedBuffer
enelson1001 Nov 17, 2019
3279ac5
Removed nulptr test and alignment test
enelson1001 Nov 17, 2019
4d3fec0
Updated includes
enelson1001 Nov 19, 2019
b597270
updated includes
enelson1001 Nov 19, 2019
16195e7
updated includes
enelson1001 Nov 19, 2019
86c80d6
updated includes
enelson1001 Nov 19, 2019
94ed235
updated includes
enelson1001 Nov 19, 2019
775b16f
updated includes
enelson1001 Nov 19, 2019
86fe541
updated includes
enelson1001 Nov 19, 2019
11c8658
updated includes
enelson1001 Nov 19, 2019
1bca037
updated includes
enelson1001 Nov 19, 2019
679454a
added check in destructor for inflight spi trans
enelson1001 Nov 19, 2019
d354c18
updated includes
enelson1001 Nov 19, 2019
1566326
updated includes
enelson1001 Nov 19, 2019
ed0cd62
corrected spelling
enelson1001 Nov 19, 2019
f735f15
Merge branch 'master' into master
enelson1001 Nov 19, 2019
4b26f32
Merge branch 'master' into master
PerMalmberg Nov 19, 2019
1bd34b2
added missing spi_common.h
enelson1001 Nov 20, 2019
eb41967
fixed missing quote in include
enelson1001 Nov 20, 2019
3a30a9f
formatted file
enelson1001 Nov 20, 2019
24e24bd
formated file
enelson1001 Nov 20, 2019
166c08a
added missing quote to include
enelson1001 Nov 20, 2019
b91de89
formatted file
enelson1001 Nov 20, 2019
8cfabd7
formatted file
enelson1001 Nov 20, 2019
4624ace
add spi_common.c
enelson1001 Nov 20, 2019
3b98e8c
added lldesc.h for spi_common
enelson1001 Nov 20, 2019
78f18ed
formatted file
enelson1001 Nov 20, 2019
9a7e557
formatted again
enelson1001 Nov 20, 2019
64f5569
format again
enelson1001 Nov 20, 2019
5aea592
Merge branch 'master' of https://github.com/enelson1001/Smooth
enelson1001 Nov 20, 2019
420b58f
not required
enelson1001 Nov 20, 2019
4d5fdfe
attempt 1
enelson1001 Nov 20, 2019
cba7404
attempt #2
enelson1001 Nov 20, 2019
0301a22
attempt #3
enelson1001 Nov 20, 2019
f62e8c9
attempt #4
enelson1001 Nov 20, 2019
403ed06
attempt #5
enelson1001 Nov 20, 2019
dcd7893
add spi_master
enelson1001 Nov 20, 2019
75e0166
added spi_common.h
enelson1001 Nov 20, 2019
a438b8f
Merge branch 'master' of https://github.com/enelson1001/Smooth
enelson1001 Nov 20, 2019
a6d9de9
spi updates, add mock-idf files, update test files
enelson1001 Nov 22, 2019
02f9e8f
add hep to mock-idf
enelson1001 Nov 22, 2019
2eb524b
Added name to contributors
enelson1001 Nov 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/smooth/application/display/ILI9341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ using namespace smooth::core::io::spi;

namespace smooth::application::display
{
static const char TAG[] = "ILI9314:";
static const char* TAG = "ILI9314";
static const bool PIN_HIGH = true;
static const bool PIN_LOW = false;
static const bool GOOD = true;
static const gpio_num_t CHIP_SELECT_NOT_USED = static_cast<gpio_num_t>(-1);

ILI9341::ILI9341(std::mutex& guard,
gpio_num_t chip_select_pin,
Expand Down Expand Up @@ -72,7 +70,7 @@ namespace smooth::application::display
bool ILI9341::init(spi_host_device_t host)
{
// spi_transaction will not control chip select
bool res = initialize(host, CHIP_SELECT_NOT_USED);
bool res = initialize(host, GPIO_NUM_NC);

return res;
}
Expand Down
16 changes: 8 additions & 8 deletions lib/smooth/application/io/i2c/BME280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace smooth::core::logging;

namespace smooth::application::sensor
{
static const char TAG[] = "BME280SPI:";
static const char* TAG = "BME280SPI";

BME280::BME280(i2c_port_t port, uint8_t address, std::mutex& guard)
: I2CMasterDevice(port, address, guard)
Expand Down Expand Up @@ -95,9 +95,9 @@ namespace smooth::application::sensor
core::util::FixedBuffer<uint8_t, 1> rest;
core::util::FixedBuffer<uint8_t, 1> config;

auto res = read(address, BME280Core::CTRL_HUM_REG, hum) &&
read(address, BME280Core::CTRL_MEAS_REG, rest) &&
read(address, BME280Core::CONFIG_REG, config);
auto res = read(address, BME280Core::CTRL_HUM_REG, hum)
&& read(address, BME280Core::CTRL_MEAS_REG, rest)
&& read(address, BME280Core::CONFIG_REG, config);

if (res)
{
Expand Down Expand Up @@ -125,8 +125,8 @@ namespace smooth::application::sensor
core::util::FixedBuffer<uint8_t, 26> calib00_calib25_data; // 0x88-0xA1
core::util::FixedBuffer<uint8_t, 7> calib26_calib32_data; // 0xE1-0xE7

trimming_read = read(address, BME280Core::CALIB00_REG, calib00_calib25_data) &&
read(address, BME280Core::CALIB26_REG, calib26_calib32_data);
trimming_read = read(address, BME280Core::CALIB00_REG, calib00_calib25_data)
&& read(address, BME280Core::CALIB26_REG, calib26_calib32_data);

if (trimming_read)
{
Expand Down Expand Up @@ -165,8 +165,8 @@ namespace smooth::application::sensor
pressure = 0;
temperature = 0;

bool res = read_trimming_parameters();
res = res && read(address, BME280Core::PRESS_MSB_REG, measurement_data);
bool res = read_trimming_parameters()
&& read(address, BME280Core::PRESS_MSB_REG, measurement_data);

if (res)
{
Expand Down
71 changes: 51 additions & 20 deletions lib/smooth/application/io/spi/BME280SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ using namespace smooth::core::io::spi;

namespace smooth::application::sensor
{
static const char TAG[] = "BME280SPI:";
static const char* TAG = "BME280SPI";

BME280SPI::BME280SPI(std::mutex& guard,
gpio_num_t chip_select_pin,
Expand Down Expand Up @@ -94,7 +94,12 @@ namespace smooth::application::sensor

uint8_t BME280SPI::read_id()
{
alignas(4) std::array<uint8_t, 4> rxdata;
std::array<uint8_t, 4> rxdata;

// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
// see esp-idf/components/driver/spi_master.c line 865
//static_assert(&rxdata % 4 == 0, "Error:c rxdata not 32 bit aligned ");

auto res = read(BME280Core::ID_REG, rxdata.data(), 2);

return res ? rxdata.at(1) : 0;
Expand All @@ -116,8 +121,11 @@ namespace smooth::application::sensor

bool BME280SPI::read_status(bool& is_measuring, bool& updating_from_nvm)
{
std::array<uint8_t, 4> rxdata;

// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
alignas(4) std::array<uint8_t, 4> rxdata;
// see esp-idf/components/driver/spi_master.c line 865
//static_assert(&rxdata % 4 == 0, "Error: rxdata not 32 bit aligned ");

auto res = read(BME280Core::STATUS_REG, rxdata.data(), 2);

Expand Down Expand Up @@ -164,17 +172,26 @@ namespace smooth::application::sensor
BME280Core::FilterCoeff& filter,
BME280Core::SpiInterface& spi_interface)
{
// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.c
alignas(4) core::util::FixedBuffer<uint8_t, 4> ctrl_hum_data;
alignas(4) core::util::FixedBuffer<uint8_t, 4> ctrl_meas_data;
alignas(4) core::util::FixedBuffer<uint8_t, 4> config_data;
core::util::FixedBuffer<uint8_t, 4> ctrl_hum_data;
core::util::FixedBuffer<uint8_t, 4> ctrl_meas_data;
core::util::FixedBuffer<uint8_t, 4> config_data;

// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
// see esp-idf/components/driver/spi_master.c line 865
//static_assert(ctrl_hum_data % 4 == 0, "Error: ctrl_hum_data not 32 bit aligned");
//static_assert(ctrl_meas_data % 4 == 0, "Error: ctrl_meas_data not 32 bit aligned");
//static_assert(config_data % 4 == 0, "Error: config_data not 32 bit aligned");

auto res = read(BME280Core::CTRL_HUM_REG, ctrl_hum_data.data(), 2) &&
read(BME280Core::CTRL_MEAS_REG, ctrl_meas_data.data(), 2) &&
read(BME280Core::CONFIG_REG, config_data.data(), 2);
auto res = read(BME280Core::CTRL_HUM_REG, ctrl_hum_data.data(), 2)
&& read(BME280Core::CTRL_MEAS_REG, ctrl_meas_data.data(), 2)
&& read(BME280Core::CONFIG_REG, config_data.data(), 2);

if (res)
{
// Since we are using 4-line spi (full duplex) the sck clocks both data out
// and data in at the same time. The first byte going out is the register we want
// to read and so the first byte received is garbage or dummy byte. So we
// will pass the 2nd byte received to get_configuration_settings.
bme280_core.get_configuration_settings(ctrl_hum_data[1],
ctrl_meas_data[1],
config_data[1],
Expand All @@ -194,17 +211,25 @@ namespace smooth::application::sensor
{
if (!trimming_read)
{
core::util::FixedBuffer<uint8_t, 32> calib00_calib25_data; // 0x88-0xA1
core::util::FixedBuffer<uint8_t, 8> calib26_calib32_data; // 0xE1-0xE7

// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
alignas(4) core::util::FixedBuffer<uint8_t, 32> calib00_calib25_data; // 0x88-0xA1
alignas(4) core::util::FixedBuffer<uint8_t, 8> calib26_calib32_data; // 0xE1-0xE7
// see esp-idf/components/driver/spi_master.c line 865
//static_assert(calib00_calib25_data % 4 == 0, "Error: calib00_calib25_data not 32 bit aligned");
//static_assert(calib26_calib32_data % 4 == 0, "Error: calib26_calib32_data not 32 bit aligned");

core::util::FixedBuffer<uint8_t, 32> calibration_data;

trimming_read = read(BME280Core::CALIB00_REG, calib00_calib25_data.data(), 27) &&
read(BME280Core::CALIB26_REG, calib26_calib32_data.data(), 8);
trimming_read = read(BME280Core::CALIB00_REG, calib00_calib25_data.data(), 27)
&& read(BME280Core::CALIB26_REG, calib26_calib32_data.data(), 8);

if (trimming_read)
{
// don't copy dummy byte but copy 0x88-0x9F into calibration_data
// Since we are using 4-line spi (full duplex) the sck clocks both data out
// and data in at the same time. The first byte going out is the register we want
// to read and so the first byte received is garbage or dummy byte. So we
// don't want to copy the dummy byte but copy 0x88-0x9F into calibration_data
for (size_t i = 0; i < 24; i++)
{
calibration_data[i] = calib00_calib25_data[i + 1];
Expand Down Expand Up @@ -232,17 +257,23 @@ namespace smooth::application::sensor

bool BME280SPI::read_measurements(float& humidity, float& pressure, float& temperature)
{
core::util::FixedBuffer<uint8_t, 12> temp_data{};

// The spi rx buffer need to be length of multiples of 32 bits to avoid heap corruption.
alignas(4) core::util::FixedBuffer<uint8_t, 12> temp_data{};
core::util::FixedBuffer<uint8_t, 8> measurement_data;
// see esp-idf/components/driver/spi_master.c line 865
//static_assert(temp_data % 4 == 0, "Error: "temp_data not 32 bit aligned");

bool res = read_trimming_parameters();
core::util::FixedBuffer<uint8_t, 8> measurement_data;

res = res && read(BME280Core::PRESS_MSB_REG, temp_data.data(), 9);
bool res = read_trimming_parameters()
&& read(BME280Core::PRESS_MSB_REG, temp_data.data(), 9);

if (res)
{
// don't copy dummy byte but copy actual data into measurement_data
// Since we are using 4-line spi (full duplex) the sck clocks both data out
// and data in at the same time. The first byte going out is the register we want
// to read and so the first byte received is garbage or dummy byte. So we
// don't want to copy the dummy byte but copy actual data into measurement_data
for (size_t i = 0; i < 8; i++)
{
measurement_data[i] = temp_data[i + 1];
Expand Down
6 changes: 3 additions & 3 deletions lib/smooth/include/smooth/application/display/ILI9341.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ limitations under the License.
16MHz but data sheet recommends 10MHz.

NOTE 3: Most applications will not need the ability to read regsiters and are
only writing to the display. In this case MISO can be set to -1. Also the spi
clock speed can be increased to either 26MHz or 40MHz. The 2 displays I tested
this driver with operated at 40MHz with no problem.
only writing to the display. In this case MISO can be set to GPIO_NUM_NC. Also
the spi clock speed can be increased to either 26MHz or 40MHz. The 2 displays I
tested this driver with operated at 40MHz with no problem.
************************************************************************************/
#pragma once

Expand Down