From 994f1f1e36aad7351328822981421d16060ac688 Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Mon, 27 Sep 2010 00:51:11 -0400 Subject: cleanups --- wirish/comm/HardwareSPI.cpp | 78 ++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'wirish/comm/HardwareSPI.cpp') diff --git a/wirish/comm/HardwareSPI.cpp b/wirish/comm/HardwareSPI.cpp index 5f42db7..5d04ddf 100644 --- a/wirish/comm/HardwareSPI.cpp +++ b/wirish/comm/HardwareSPI.cpp @@ -1,4 +1,4 @@ -/* ***************************************************************************** +/****************************************************************************** * The MIT License * * Copyright (c) 2010 Perry Hung. @@ -20,7 +20,7 @@ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. - * ****************************************************************************/ + *****************************************************************************/ /** * @brief HardwareSPI "wiring-like" api for SPI @@ -52,14 +52,14 @@ #include "HardwareSPI.h" static const uint32 prescaleFactors[MAX_SPI_FREQS] = { - SPI_PRESCALE_2, // SPI_18MHZ - SPI_PRESCALE_4, // SPI_9MHZ - SPI_PRESCALE_8, // SPI_4_5MHZ - SPI_PRESCALE_16, // SPI_2_25MHZ - SPI_PRESCALE_32, // SPI_1_125MHZ - SPI_PRESCALE_64, // SPI_562_500KHZ - SPI_PRESCALE_128, // SPI_281_250KHZ - SPI_PRESCALE_256, // SPI_140_625KHZ + SPI_PRESCALE_2, // SPI_18MHZ + SPI_PRESCALE_4, // SPI_9MHZ + SPI_PRESCALE_8, // SPI_4_5MHZ + SPI_PRESCALE_16, // SPI_2_25MHZ + SPI_PRESCALE_32, // SPI_1_125MHZ + SPI_PRESCALE_64, // SPI_562_500KHZ + SPI_PRESCALE_128, // SPI_281_250KHZ + SPI_PRESCALE_256, // SPI_140_625KHZ }; /** @@ -78,37 +78,38 @@ static const uint32 prescaleFactors[MAX_SPI_FREQS] = { * @param mode SPI standard CPOL and CPHA levels */ void HardwareSPI::begin(SPIFrequency freq, uint32 endianness, uint32 mode) { - uint32 spi_num = this->spi_num; - uint32 prescale; - - if ((freq >= MAX_SPI_FREQS) || - !((endianness == LSBFIRST) || - (endianness == MSBFIRST)) || - (mode >= 4)) { - return; - } - - if (spi_num == 1) { - /* SPI1 is too fast for 140625 */ - if (freq == SPI_140_625KHZ) { - return; - } - - /* Turn off PWM on shared pins */ - timer_set_mode(TIMER3, 2, TIMER_DISABLED); - timer_set_mode(TIMER3, 1, TIMER_DISABLED); - } - - endianness = (endianness == LSBFIRST) ? SPI_LSBFIRST : SPI_MSBFIRST; - prescale = (spi_num == 1) ? prescaleFactors[freq + 1] : prescaleFactors[freq]; - - spi_init(spi_num, prescale, endianness, 0); + uint32 spi_num = this->spi_num; + uint32 prescale; + + if ((freq >= MAX_SPI_FREQS) || + !((endianness == LSBFIRST) || + (endianness == MSBFIRST)) || + (mode >= 4)) { + return; + } + + if (spi_num == 1) { + /* SPI1 is too fast for 140625 */ + if (freq == SPI_140_625KHZ) { + return; + } + + /* Turn off PWM on shared pins */ + timer_set_mode(TIMER3, 2, TIMER_DISABLED); + timer_set_mode(TIMER3, 1, TIMER_DISABLED); + } + + endianness = (endianness == LSBFIRST) ? SPI_LSBFIRST : SPI_MSBFIRST; + prescale = (spi_num == 1) ? + prescaleFactors[freq + 1] : + prescaleFactors[freq]; + + spi_init(spi_num, prescale, endianness, 0); } /** - * @brief Initialize a SPI peripheral with a default speed of 1.125 MHZ, MSBFIRST, - * mode 0 - * @param mode SPI standard CPOL and CPHA levels + * @brief Initialize a SPI peripheral with a default speed of 1.125 + * MHZ, MSBFIRST, mode 0 */ void HardwareSPI::begin(void) { begin(SPI_1_125MHZ, MSBFIRST, 0); @@ -126,7 +127,6 @@ uint8 HardwareSPI::send(uint8 *buf, uint32 len) { return spi_tx(this->spi_num, buf, len); } - /** * @brief read a byte from the spi peripheral * @return byte in the buffer -- cgit v1.2.3