Lab 6 code.

Dependencies:   mbed

Fork of WaG by GroupA

Revision:
17:75d567b60214
Child:
18:0e281922212c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spi.cpp	Thu Mar 01 17:31:04 2018 +0000
@@ -0,0 +1,49 @@
+/******************************************************************************
+* EECS 397
+*
+* Assignment Name: Lab 5: WaG
+* 
+* Authors: Sam Morrison and Phong Nguyen 
+* File name: spi.cpp
+* Purpose: Driver for SPI functions
+*
+* Created: 03/01/2018
+* Last Modified: 03/01/2018
+*
+******************************************************************************/
+
+#include "mbed.h"
+#include "io_pins.h"
+#include "spi.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+extern spi_cfg as1107 {
+    1,
+    DSP_AS1107_NCS,
+    0,
+    1000000,
+    16,
+};
+
+extern spi_cfg drv8806 {
+    2,
+    STP_DRV8806_NCS,
+    0,
+    1000000,
+    8,
+};
+
+void spi_send(struct spi_cfg spi_config, int spi_data) {
+    static int previous_id = SPI_NO_ID;
+    spi_config.spi_ncs = 1;
+    if (previous_id != spi_config.spi_id) {
+        //send config data to master, update previous id with current id
+        previous_id = spi_config.spi_id;
+    }
+    spi_config.spi_ncs = 0;
+    wag_spi.write(spi_data);
+    spi_config.spi_ncs = 1;
+}
+