diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2011-05-04 17:23:54 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2011-05-04 17:23:54 -0400 |
commit | f35c9f71385ba0629e1e3744d08da2cf442b3e9d (patch) | |
tree | 74d64293a8dc49cfdd5bb8bd28666100519c18f9 /wirish | |
parent | dde41df8c16fd92aa1b267383ae689c678e7758d (diff) | |
download | librambutan-f35c9f71385ba0629e1e3744d08da2cf442b3e9d.tar.gz librambutan-f35c9f71385ba0629e1e3744d08da2cf442b3e9d.zip |
SPI fixups.
Initial post-review changes based on thread here:
https://github.com/leaflabs/libmaple/commit/77f707d7b87fce284945fc9fe21c824c18c4c93d#comments
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/comm/HardwareSPI.cpp | 33 | ||||
-rw-r--r-- | wirish/comm/HardwareSPI.h | 2 |
2 files changed, 10 insertions, 25 deletions
diff --git a/wirish/comm/HardwareSPI.cpp b/wirish/comm/HardwareSPI.cpp index 1b36d21..54b7ab3 100644 --- a/wirish/comm/HardwareSPI.cpp +++ b/wirish/comm/HardwareSPI.cpp @@ -125,11 +125,10 @@ void HardwareSPI::read(uint8 *buf, uint32 len) { } void HardwareSPI::write(uint8 byte) { - uint8 buf[] = {byte}; - this->write(buf, 1); + this->write(&byte, 1); } -void HardwareSPI::write(uint8 *data, uint32 length) { +void HardwareSPI::write(const uint8 *data, uint32 length) { uint32 txed = 0; while (txed < length) { txed += spi_tx(this->spi_d, data + txed, length - txed); @@ -152,7 +151,6 @@ uint8 HardwareSPI::send(uint8 data) { uint8 HardwareSPI::send(uint8 *buf, uint32 len) { if (len == 0) { - ASSERT(0); return 0; } uint32 txed = 0; @@ -183,11 +181,6 @@ static void enable_device(spi_dev *dev, SPIFrequency freq, spi_cfg_flag endianness, spi_mode mode) { - if (freq >= MAX_SPI_FREQS) { - ASSERT(0); - return; - } - spi_baud_rate baud = determine_baud_rate(dev, freq); uint32 cfg_flags = (endianness | SPI_DFF_8_BIT | SPI_SW_SLAVE | (as_master ? SPI_SOFT_SS : 0)); @@ -261,21 +254,13 @@ static void configure_gpios(spi_dev *dev, bool as_master) { disable_pwm(misoi); disable_pwm(mosii); - if (as_master) { - spi_master_gpio_cfg(nssi->gpio_device, - scki->gpio_device, - nssi->gpio_bit, - scki->gpio_bit, - misoi->gpio_bit, - mosii->gpio_bit); - } else { - spi_slave_gpio_cfg(nssi->gpio_device, - scki->gpio_device, - nssi->gpio_bit, - scki->gpio_bit, - misoi->gpio_bit, - mosii->gpio_bit); - } + spi_gpio_cfg(as_master, + nssi->gpio_device, + nssi->gpio_bit, + scki->gpio_device, + scki->gpio_bit, + misoi->gpio_bit, + mosii->gpio_bit); } static const spi_baud_rate baud_rates[MAX_SPI_FREQS] __FLASH__ = { diff --git a/wirish/comm/HardwareSPI.h b/wirish/comm/HardwareSPI.h index 1b2a966..3a6def5 100644 --- a/wirish/comm/HardwareSPI.h +++ b/wirish/comm/HardwareSPI.h @@ -140,7 +140,7 @@ public: * @param buffer Bytes to transmit. * @param length Number of bytes in buffer to transmit. */ - void write(uint8 *buffer, uint32 length); + void write(const uint8 *buffer, uint32 length); /** * @brief Transmit a byte, then return the next unread byte. |