Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 0:6c56fb4bc5f0 1 #include "mbed.h"
nexpaq 0:6c56fb4bc5f0 2
nexpaq 0:6c56fb4bc5f0 3 #if !DEVICE_SPISLAVE
nexpaq 0:6c56fb4bc5f0 4 #error [NOT_SUPPORTED] SPI Slave not supported
nexpaq 0:6c56fb4bc5f0 5 #endif
nexpaq 0:6c56fb4bc5f0 6
nexpaq 0:6c56fb4bc5f0 7 #if defined(TARGET_KL25Z)
nexpaq 0:6c56fb4bc5f0 8 SPISlave device(PTD2, PTD3, PTD1, PTD0); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 9 #elif defined(TARGET_nRF51822)
nexpaq 0:6c56fb4bc5f0 10 SPISlave device(p12, p13, p15, p14); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 11 #elif defined(TARGET_LPC812)
nexpaq 0:6c56fb4bc5f0 12 SPISlave device(P0_14, P0_15, P0_12, P0_13); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 13 #elif defined(TARGET_FF_ARDUINO)
nexpaq 0:6c56fb4bc5f0 14 SPISlave device(D11, D12, D13, D10); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 15 #elif defined(TARGET_LPC1114)
nexpaq 0:6c56fb4bc5f0 16 SPISlave device(dp2, dp1, dp6, dp25); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 17 #elif defined(TARGET_SAMR21G18A)
nexpaq 0:6c56fb4bc5f0 18 SPISlave device(PB22, PB02, PB23, PB03); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 19 #elif defined(TARGET_SAMD21J18A) || defined(TARGET_SAMD21G18A) || defined(TARGET_SAML21J18A)
nexpaq 0:6c56fb4bc5f0 20 SPISlave device(PA18, PA16, PA19, PA17); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 21 #elif defined(TARGET_SAMG55J19)
nexpaq 0:6c56fb4bc5f0 22 SPISlave device(PA10, PA09, PB00, PA25); // mosi, miso, sclk cs
nexpaq 0:6c56fb4bc5f0 23 #else
nexpaq 0:6c56fb4bc5f0 24 SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
nexpaq 0:6c56fb4bc5f0 25 #endif
nexpaq 0:6c56fb4bc5f0 26
nexpaq 0:6c56fb4bc5f0 27
nexpaq 0:6c56fb4bc5f0 28 int main() {
nexpaq 0:6c56fb4bc5f0 29 uint8_t resp = 0;
nexpaq 0:6c56fb4bc5f0 30
nexpaq 0:6c56fb4bc5f0 31 device.reply(resp); // Prime SPI with first reply
nexpaq 0:6c56fb4bc5f0 32
nexpaq 0:6c56fb4bc5f0 33 while(1) {
nexpaq 0:6c56fb4bc5f0 34 if(device.receive()) {
nexpaq 0:6c56fb4bc5f0 35 resp = device.read(); // Read byte from master and add 1
nexpaq 0:6c56fb4bc5f0 36 device.reply(resp); // Make this the next reply
nexpaq 0:6c56fb4bc5f0 37 }
nexpaq 0:6c56fb4bc5f0 38 }
nexpaq 0:6c56fb4bc5f0 39 }