From 05db82341770439061e780788822e55ecc11ab39 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Sat, 14 Dec 2019 17:25:54 -0500 Subject: [PATCH] enable control of SPI through the serial interface. --- CHANGELOG.md | 4 ++++ src/commandconstants.hpp | 27 +++++++++++++++++++++++++++ src/main.cpp | 9 ++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98e07e7..a9e26da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.0.9 + +* Enable control of SPI through the interface. + ### 0.0.8 * Use git describe --tag to correctly identify the tags diff --git a/src/commandconstants.hpp b/src/commandconstants.hpp index e38abee..471a56e 100644 --- a/src/commandconstants.hpp +++ b/src/commandconstants.hpp @@ -28,6 +28,18 @@ int analog_write(CommandRouter *cmd, int argc, const char **argv); int analog_write_frequency(CommandRouter *cmd, int argc, const char **argv); int analog_write_resolution(CommandRouter *cmd, int argc, const char **argv); +// SPI support +int spi_begin(CommandRouter *cmd, int argc, const char **argv); +int spi_end(CommandRouter *cmd, int argc, const char **argv); +int spi_set_mosi(CommandRouter *cmd, int argc, const char **argv); +int spi_set_miso(CommandRouter *cmd, int argc, const char **argv); +int spi_set_sck(CommandRouter *cmd, int argc, const char **argv); +int spi_settings(CommandRouter *cmd, int argc, const char **argv); +int spi_begin_transaction(CommandRouter *cmd, int argc, const char **argv); +int spi_end_transaction(CommandRouter *cmd, int argc, const char **argv); +int spi_transfer(CommandRouter *cmd, int argc, const char **argv); +int spi_transfer_bulk(CommandRouter *cmd, int argc, const char **argv); +int spi_set_clock_divider(CommandRouter *cmd, int argc, const char **argv); // Syntax is: {short command, description, syntax} command_item_t command_list[] = { {"?", "Display help info", "?", command_help_func}, @@ -74,4 +86,19 @@ command_item_t command_list[] = { "analog_write_frequency pin frequency", analog_write_frequency}, {"analog_write_resolution", "Write the resolution of the PWM timer", "analog_write_resolution bitdepth", analog_write_resolution}, + {"spi_begin", "SPI Begin", "spi_begin", spi_begin}, + {"spi_end", "SPI End", "spi_end", spi_begin}, + {"spi_set_mosi", "SPI set MOSI", "spi_set_mosi mosi", spi_set_mosi}, + {"spi_set_miso", "SPI set MISO ", " spi_set_miso miso", spi_set_miso}, + {"spi_set_sck", "SPI set SCK ", " spi_set_sck sck", spi_set_sck}, + {"spi_settings", "SPI set setting", + "spi_settings frequency bitOrder dataMode", spi_settings}, + {"spi_begin_transaction", "spi_begin_transaction", "spi_begin_transaction", + spi_begin_transaction}, + {"spi_end_transaction", "spi_end_transaction", "spi_end_transaction", + spi_end_transaction}, + {"spi_transfer", "SPI Transfer 8bits of data", "spi_transfer data", + spi_transfer}, + {"spi_transfer_bulk", "SPI transfer multiple sets of 8 bits of data", + "spi_transfer_bulk data[0] data[1] data[2] [...]", spi_transfer_bulk}, {nullptr, nullptr, nullptr, nullptr}}; diff --git a/src/main.cpp b/src/main.cpp index 5b15124..9d6297e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -271,6 +271,13 @@ int spi_begin(CommandRouter *cmd, int argc, const char **argv) { SPI.begin(); return 0; } +int spi_end(CommandRouter *cmd, int argc, const char **argv) { + if (argc != 1) { + return EINVAL; + } + SPI.end(); + return 0; +} int spi_set_mosi(CommandRouter *cmd, int argc, const char **argv) { if (argc != 2) { @@ -383,4 +390,4 @@ void loop() { if (Serial.available()) { cmd.processSerialStream(); } -} \ No newline at end of file +}