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.
Diff: main.cpp
- Revision:
- 3:7954489d9f8a
- Parent:
- 0:a74ad5b8dc7b
- Child:
- 4:e7e194f58f65
diff -r 7add4b4a96d7 -r 7954489d9f8a main.cpp --- a/main.cpp Tue Oct 05 09:59:20 2021 +0000 +++ b/main.cpp Tue Oct 05 10:53:54 2021 +0000 @@ -33,43 +33,72 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2019-01-10-7CBSD SLA -*/ + -#include "mbed.h" +/*============= I N C L U D E S =============*/ +#include "admx200x.h" +#include "platform_drivers.h" +#include "serial_comm.h" +#include "spi_extra.h" +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> -// LED Blinking rate in milliseconds (Note: need to define the unit of a time duration i.e. seconds(s) or milliseconds(ms)) -#define SLEEP_TIME 500ms +/** This is kept global and non-static because as test codes require this*/ +Admx200xDev admx200xDev; + +static int32_t SPIInit(spi_desc **pSpiDesc); -// Initialise the digital pin that controls LED1 -DigitalOut led(LED1); -// Initialise the serial object with TX and RX pins -static BufferedSerial serial_port(USBTX, USBRX); +/** + * Function to initialize SPI + */ +int32_t SPIInit(spi_desc **pSpiDesc) +{ + int32_t status; -// The File handler is needed to allow printf commands to write to the terminal -FileHandle *mbed::mbed_override_console(int fd) -{ - return &serial_port; + // Init SPI extra parameters structure + mbed_spi_init_param spiInitExtraParams = {.spi_clk_pin = SPI_SCK, + .spi_miso_pin = SPI_MISO, + .spi_mosi_pin = SPI_MOSI}; + + spi_init_param spiInit = { + 25000000, // Max SPI Speed + SPI_SS, // Chip Select pin + SPI_MODE_0, + &spiInitExtraParams, // SPI extra configurations + }; + + status = spi_init(pSpiDesc, &spiInit); + + return status; } -// main() runs in its own thread in the OS int main() { - // printing the Mbed OS version this example was written to the console - printf("This Application has been developed on Mbed OS version 6.4\r\n"); - - // printing the actual Mbed OS version that this application is using to the console. - printf( - "Mbed OS version %d.%d.%d is what this applicaiton is currently using\r\n", - MBED_MAJOR_VERSION, - MBED_MINOR_VERSION, - MBED_PATCH_VERSION - ); - - // The loop will toggle the LED every 500ms(SLEEP_TIME = 500ms) and print LED1s current state to the terminal - while (1) { - led = !led; // toggle LED1 state - printf("LED1 state: %d \r\n", (uint8_t)led); - ThisThread::sleep_for(SLEEP_TIME); + int32_t status = 0; + static spi_desc spiDesc; + spi_desc *pSpi = &spiDesc; + Admx200xDev *pADmx2001 = &admx200xDev; + status |= SPIInit(&pSpi); + status |= CliInit(); + status |= Admx200xInit(pADmx2001, pSpi); + + mdelay(100); + + /* Initialize the ADMX200x application */ + if (status != 0) + { + printf("Error setting up ADMX200X \r\n\r\n"); } + else + { + while (status == 0) + { + CliInterface(); + } + } + + status = spi_remove(pSpi); + + return status; } -