Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: UniGraphic mbed vt100
Diff: af_utils/mbedSPI.cpp
- Revision:
- 0:774324cbc5a6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/af_utils/mbedSPI.cpp Fri Mar 02 07:56:09 2018 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+#include "vt100.h"
+#include "afSPI.h"
+#include "mbedSPI.h"
+
+#if defined (TARGET_KL25Z) || defined (TARGET_TEENSY3_1)
+ #ifndef SPI0_C1
+ #define SPI0_C1 (*(uint8_t *)0x40076000)
+ #endif
+#endif
+/*
+class mbedSPI : public afSPI {
+public:
+ mbedSPI(PinName mosi, PinName miso, PinName sckl, PinName cs) ;
+ virtual void begin() ;
+ virtual void beginSPI() ;
+ virtual void endSPI() ;
+ virtual void transfer(char *bytes,int len) ;
+private:
+ SPI _spi ;
+ DigitalOut _cs ;
+} ;
+*/
+
+mbedSPI::mbedSPI(PinName mosi, PinName miso, PinName sckl, PinName cs) :
+ _spi(mosi, miso, sckl), _cs(cs, 1)
+{
+ _spi.format(8, 0) ;
+ _spi.frequency(1000000) ; /* 1MHz */
+
+#if defined (TARGET_KL25Z) || defined (TARGET_TEENSY3_1)
+ #ifndef SPI0_C1
+ #define SPI0_C1 (*(uint8_t *)0x40076000)
+ #endif
+// SPI0_C1 |= 0x01 ; /* LSB First */
+// SPI0_C1 &= 0xFE ; /* MSB First */
+#endif
+
+}
+
+void mbedSPI::begin(void)
+{
+}
+
+void mbedSPI::beginSPI()
+{
+// printf("+") ; fflush(stdout) ;
+ _cs = 0 ;
+ SPI0_C1 |= 0x01 ; /* LSB First */
+ wait_us(1) ;
+}
+
+void mbedSPI::endSPI()
+{
+ _cs = 1 ;
+ SPI0_C1 &= 0xFE ; /* MSB First */
+ wait_us(1) ;
+// printf("-") ; fflush(stdout) ;
+}
+
+/**
+ * on 17-Jan-2018 disable/enable irq added
+ * before and after of each _spi.writes
+ */
+void mbedSPI::transfer(char *bytes, int len)
+{
+ int i ;
+ for (i = 0 ; i < len ; i++ ) {
+ __disable_irq() ; // Disable Interrupts
+ bytes[i] = _spi.write(bytes[i]) ;
+ __enable_irq() ; // Enable Interrupts
+ }
+}
+