Example program for EVAL-ADMX2001
Dependencies: ADMX2001
main.cpp@3:7954489d9f8a, 2021-10-05 (annotated)
- Committer:
- nsheth
- Date:
- Tue Oct 05 10:53:54 2021 +0000
- Revision:
- 3:7954489d9f8a
- Parent:
- 0:a74ad5b8dc7b
- Child:
- 4:e7e194f58f65
Minor changes to main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kjansen45 | 0:a74ad5b8dc7b | 1 | /* Copyright (c) 2019 Analog Devices, Inc. All rights reserved. |
Kjansen45 | 0:a74ad5b8dc7b | 2 | |
Kjansen45 | 0:a74ad5b8dc7b | 3 | Redistribution and use in source and binary forms, with or without modification, |
Kjansen45 | 0:a74ad5b8dc7b | 4 | are permitted provided that the following conditions are met: |
Kjansen45 | 0:a74ad5b8dc7b | 5 | - Redistributions of source code must retain the above copyright notice, |
Kjansen45 | 0:a74ad5b8dc7b | 6 | this list of conditions and the following disclaimer. |
Kjansen45 | 0:a74ad5b8dc7b | 7 | - Redistributions in binary form must reproduce the above copyright notice, |
Kjansen45 | 0:a74ad5b8dc7b | 8 | this list of conditions and the following disclaimer in the documentation |
Kjansen45 | 0:a74ad5b8dc7b | 9 | and/or other materials provided with the distribution. |
Kjansen45 | 0:a74ad5b8dc7b | 10 | - Modified versions of the software must be conspicuously marked as such. |
Kjansen45 | 0:a74ad5b8dc7b | 11 | - This software is licensed solely and exclusively for use with processors/products |
Kjansen45 | 0:a74ad5b8dc7b | 12 | manufactured by or for Analog Devices, Inc. |
Kjansen45 | 0:a74ad5b8dc7b | 13 | - This software may not be combined or merged with other code in any manner |
Kjansen45 | 0:a74ad5b8dc7b | 14 | that would cause the software to become subject to terms and conditions which |
Kjansen45 | 0:a74ad5b8dc7b | 15 | differ from those listed here. |
Kjansen45 | 0:a74ad5b8dc7b | 16 | - Neither the name of Analog Devices, Inc. nor the names of its contributors |
Kjansen45 | 0:a74ad5b8dc7b | 17 | may be used to endorse or promote products derived from this software without |
Kjansen45 | 0:a74ad5b8dc7b | 18 | specific prior written permission. |
Kjansen45 | 0:a74ad5b8dc7b | 19 | - The use of this software may or may not infringe the patent rights of one or |
Kjansen45 | 0:a74ad5b8dc7b | 20 | more patent holders. This license does not release you from the requirement |
Kjansen45 | 0:a74ad5b8dc7b | 21 | that you obtain separate licenses from these patent holders to use this software. |
Kjansen45 | 0:a74ad5b8dc7b | 22 | |
Kjansen45 | 0:a74ad5b8dc7b | 23 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND |
Kjansen45 | 0:a74ad5b8dc7b | 24 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
Kjansen45 | 0:a74ad5b8dc7b | 25 | TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN |
Kjansen45 | 0:a74ad5b8dc7b | 26 | NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
Kjansen45 | 0:a74ad5b8dc7b | 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES |
Kjansen45 | 0:a74ad5b8dc7b | 28 | (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL |
Kjansen45 | 0:a74ad5b8dc7b | 29 | PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
Kjansen45 | 0:a74ad5b8dc7b | 30 | OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
Kjansen45 | 0:a74ad5b8dc7b | 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
Kjansen45 | 0:a74ad5b8dc7b | 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
Kjansen45 | 0:a74ad5b8dc7b | 33 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Kjansen45 | 0:a74ad5b8dc7b | 34 | |
Kjansen45 | 0:a74ad5b8dc7b | 35 | 2019-01-10-7CBSD SLA |
nsheth | 3:7954489d9f8a | 36 | |
Kjansen45 | 0:a74ad5b8dc7b | 37 | |
nsheth | 3:7954489d9f8a | 38 | /*============= I N C L U D E S =============*/ |
nsheth | 3:7954489d9f8a | 39 | #include "admx200x.h" |
nsheth | 3:7954489d9f8a | 40 | #include "platform_drivers.h" |
nsheth | 3:7954489d9f8a | 41 | #include "serial_comm.h" |
nsheth | 3:7954489d9f8a | 42 | #include "spi_extra.h" |
nsheth | 3:7954489d9f8a | 43 | #include <stdint.h> |
nsheth | 3:7954489d9f8a | 44 | #include <stdio.h> |
nsheth | 3:7954489d9f8a | 45 | #include <stdlib.h> |
Kjansen45 | 0:a74ad5b8dc7b | 46 | |
nsheth | 3:7954489d9f8a | 47 | /** This is kept global and non-static because as test codes require this*/ |
nsheth | 3:7954489d9f8a | 48 | Admx200xDev admx200xDev; |
nsheth | 3:7954489d9f8a | 49 | |
nsheth | 3:7954489d9f8a | 50 | static int32_t SPIInit(spi_desc **pSpiDesc); |
Kjansen45 | 0:a74ad5b8dc7b | 51 | |
nsheth | 3:7954489d9f8a | 52 | /** |
nsheth | 3:7954489d9f8a | 53 | * Function to initialize SPI |
nsheth | 3:7954489d9f8a | 54 | */ |
nsheth | 3:7954489d9f8a | 55 | int32_t SPIInit(spi_desc **pSpiDesc) |
nsheth | 3:7954489d9f8a | 56 | { |
nsheth | 3:7954489d9f8a | 57 | int32_t status; |
Kjansen45 | 0:a74ad5b8dc7b | 58 | |
nsheth | 3:7954489d9f8a | 59 | // Init SPI extra parameters structure |
nsheth | 3:7954489d9f8a | 60 | mbed_spi_init_param spiInitExtraParams = {.spi_clk_pin = SPI_SCK, |
nsheth | 3:7954489d9f8a | 61 | .spi_miso_pin = SPI_MISO, |
nsheth | 3:7954489d9f8a | 62 | .spi_mosi_pin = SPI_MOSI}; |
nsheth | 3:7954489d9f8a | 63 | |
nsheth | 3:7954489d9f8a | 64 | spi_init_param spiInit = { |
nsheth | 3:7954489d9f8a | 65 | 25000000, // Max SPI Speed |
nsheth | 3:7954489d9f8a | 66 | SPI_SS, // Chip Select pin |
nsheth | 3:7954489d9f8a | 67 | SPI_MODE_0, |
nsheth | 3:7954489d9f8a | 68 | &spiInitExtraParams, // SPI extra configurations |
nsheth | 3:7954489d9f8a | 69 | }; |
nsheth | 3:7954489d9f8a | 70 | |
nsheth | 3:7954489d9f8a | 71 | status = spi_init(pSpiDesc, &spiInit); |
nsheth | 3:7954489d9f8a | 72 | |
nsheth | 3:7954489d9f8a | 73 | return status; |
Kjansen45 | 0:a74ad5b8dc7b | 74 | } |
Kjansen45 | 0:a74ad5b8dc7b | 75 | |
Kjansen45 | 0:a74ad5b8dc7b | 76 | int main() |
Kjansen45 | 0:a74ad5b8dc7b | 77 | { |
nsheth | 3:7954489d9f8a | 78 | int32_t status = 0; |
nsheth | 3:7954489d9f8a | 79 | static spi_desc spiDesc; |
nsheth | 3:7954489d9f8a | 80 | spi_desc *pSpi = &spiDesc; |
nsheth | 3:7954489d9f8a | 81 | Admx200xDev *pADmx2001 = &admx200xDev; |
nsheth | 3:7954489d9f8a | 82 | status |= SPIInit(&pSpi); |
nsheth | 3:7954489d9f8a | 83 | status |= CliInit(); |
nsheth | 3:7954489d9f8a | 84 | status |= Admx200xInit(pADmx2001, pSpi); |
nsheth | 3:7954489d9f8a | 85 | |
nsheth | 3:7954489d9f8a | 86 | mdelay(100); |
nsheth | 3:7954489d9f8a | 87 | |
nsheth | 3:7954489d9f8a | 88 | /* Initialize the ADMX200x application */ |
nsheth | 3:7954489d9f8a | 89 | if (status != 0) |
nsheth | 3:7954489d9f8a | 90 | { |
nsheth | 3:7954489d9f8a | 91 | printf("Error setting up ADMX200X \r\n\r\n"); |
Kjansen45 | 0:a74ad5b8dc7b | 92 | } |
nsheth | 3:7954489d9f8a | 93 | else |
nsheth | 3:7954489d9f8a | 94 | { |
nsheth | 3:7954489d9f8a | 95 | while (status == 0) |
nsheth | 3:7954489d9f8a | 96 | { |
nsheth | 3:7954489d9f8a | 97 | CliInterface(); |
nsheth | 3:7954489d9f8a | 98 | } |
nsheth | 3:7954489d9f8a | 99 | } |
nsheth | 3:7954489d9f8a | 100 | |
nsheth | 3:7954489d9f8a | 101 | status = spi_remove(pSpi); |
nsheth | 3:7954489d9f8a | 102 | |
nsheth | 3:7954489d9f8a | 103 | return status; |
Kjansen45 | 0:a74ad5b8dc7b | 104 | } |