altos: Add SPI bus parameter to ao_spi_speed
[fw/altos] / src / samd21 / ao_arch_funcs.h
index 141a9a205b7b32a144902d3912e76b6af9a85ed0..754ca3b51c3c84ecc4c8a6e2079ea64c8c8f54ba 100644 (file)
@@ -190,11 +190,11 @@ ao_enable_cs(struct samd21_port *port, uint8_t pin)
 /*
  * PA22 SERCOM3.0 -> MOSI      (DOPO 0)
  * PA23 SERCOM3.1 -> SCLK      (DOPO 0)
- * PA20 SERCOM3.3 -> MISO      (DIPO 3)
+ * PA20 SERCOM3.2 -> MISO      (DIPO 2)
  */
 #define AO_SPI_3_PA22_PA23_PA20        (3 | AO_SPI_CONFIG_0 |          \
                                 AO_SPI_DOPO_MOSI_0_SCLK_1 |    \
-                                AO_SPI_DIPO_MISO_3)
+                                AO_SPI_DIPO_MISO_2)
 #endif /* HAS_SPI_3 */
 
 #if HAS_SPI_4
@@ -282,12 +282,13 @@ ao_spi_put_bit(struct samd21_port *port, uint8_t bit, uint16_t spi_index)
 }
 
 static inline uint8_t
-ao_spi_speed(uint32_t hz)
+ao_spi_speed(int index, uint32_t hz)
 {
        int32_t baud = (int32_t) (AO_SYSCLK / (2 * hz)) - 1;
 
-       if (baud < 0)
-               baud = 0;
+       (void) index;
+       if (baud < 1)
+               baud = 1;
        if (baud > 255)
                baud = 255;
        return (uint8_t) baud;