Bluetooth enabled control of a BLDC via the Allegro MicroSystems A4960.

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_LED by Bluetooth Low Energy

Committer:
anniemao
Date:
Tue May 16 19:31:49 2017 +0000
Revision:
11:4251b62991ac
Annie Mao 2017

Who changed what in which revision?

UserRevisionLine numberNew contents of line
anniemao 11:4251b62991ac 1 /*
anniemao 11:4251b62991ac 2
anniemao 11:4251b62991ac 3 Copyright (c) 2012-2014 RedBearLab
anniemao 11:4251b62991ac 4
anniemao 11:4251b62991ac 5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
anniemao 11:4251b62991ac 6 and associated documentation files (the "Software"), to deal in the Software without restriction,
anniemao 11:4251b62991ac 7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
anniemao 11:4251b62991ac 8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
anniemao 11:4251b62991ac 9 subject to the following conditions:
anniemao 11:4251b62991ac 10 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
anniemao 11:4251b62991ac 11
anniemao 11:4251b62991ac 12 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
anniemao 11:4251b62991ac 13 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
anniemao 11:4251b62991ac 14 PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
anniemao 11:4251b62991ac 15 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
anniemao 11:4251b62991ac 16 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
anniemao 11:4251b62991ac 17
anniemao 11:4251b62991ac 18 */
anniemao 11:4251b62991ac 19
anniemao 11:4251b62991ac 20 #ifndef _SPI_MASTER_H_
anniemao 11:4251b62991ac 21 #define _SPI_MASTER_H_
anniemao 11:4251b62991ac 22
anniemao 11:4251b62991ac 23 #include "mbed.h"
anniemao 11:4251b62991ac 24
anniemao 11:4251b62991ac 25 #define SPI_FREQUENCY_125K 0x02000000UL
anniemao 11:4251b62991ac 26 #define SPI_FREQUENCY_250K 0x04000000UL
anniemao 11:4251b62991ac 27 #define SPI_FREQUENCY_500K 0x08000000UL
anniemao 11:4251b62991ac 28 #define SPI_FREQUENCY_1M 0x10000000UL
anniemao 11:4251b62991ac 29 #define SPI_FREQUENCY_2M 0x20000000UL
anniemao 11:4251b62991ac 30 #define SPI_FREQUENCY_4M 0x40000000UL
anniemao 11:4251b62991ac 31 #define SPI_FREQUENCY_8M 0x80000000UL
anniemao 11:4251b62991ac 32
anniemao 11:4251b62991ac 33 #define SPI_125K 0
anniemao 11:4251b62991ac 34 #define SPI_250K 1
anniemao 11:4251b62991ac 35 #define SPI_500K 2
anniemao 11:4251b62991ac 36 #define SPI_1M 3
anniemao 11:4251b62991ac 37 #define SPI_2M 4
anniemao 11:4251b62991ac 38 #define SPI_4M 5
anniemao 11:4251b62991ac 39 #define SPI_8M 6
anniemao 11:4251b62991ac 40
anniemao 11:4251b62991ac 41 #define SPI_MODE0 0
anniemao 11:4251b62991ac 42 #define SPI_MODE1 1
anniemao 11:4251b62991ac 43 #define SPI_MODE2 2
anniemao 11:4251b62991ac 44 #define SPI_MODE3 3
anniemao 11:4251b62991ac 45
anniemao 11:4251b62991ac 46 #define CS P0_10
anniemao 11:4251b62991ac 47 #define SCK P0_8
anniemao 11:4251b62991ac 48 #define MOSI P0_9
anniemao 11:4251b62991ac 49 #define MISO P0_11
anniemao 11:4251b62991ac 50
anniemao 11:4251b62991ac 51 typedef enum{
anniemao 11:4251b62991ac 52
anniemao 11:4251b62991ac 53 MSBFIRST = 0,
anniemao 11:4251b62991ac 54 LSBFIRST = 1
anniemao 11:4251b62991ac 55
anniemao 11:4251b62991ac 56 }BitOrder;
anniemao 11:4251b62991ac 57
anniemao 11:4251b62991ac 58 class SPIClass
anniemao 11:4251b62991ac 59 {
anniemao 11:4251b62991ac 60 public:
anniemao 11:4251b62991ac 61 SPIClass(NRF_SPI_Type *_spi);
anniemao 11:4251b62991ac 62
anniemao 11:4251b62991ac 63 void begin();
anniemao 11:4251b62991ac 64 void begin(uint32_t sck, uint32_t mosi, uint32_t miso);
anniemao 11:4251b62991ac 65 uint8_t transfer(uint8_t data);
anniemao 11:4251b62991ac 66 void endTransfer();
anniemao 11:4251b62991ac 67
anniemao 11:4251b62991ac 68 void setSPIMode( uint8_t mode );
anniemao 11:4251b62991ac 69 void setFrequency(uint8_t speed );
anniemao 11:4251b62991ac 70 void setBitORDER( BitOrder bit);
anniemao 11:4251b62991ac 71 void setCPHA( bool trailing);
anniemao 11:4251b62991ac 72 void setCPOL( bool active_low);
anniemao 11:4251b62991ac 73
anniemao 11:4251b62991ac 74
anniemao 11:4251b62991ac 75 private:
anniemao 11:4251b62991ac 76 NRF_SPI_Type *spi;
anniemao 11:4251b62991ac 77
anniemao 11:4251b62991ac 78 uint32_t SCK_Pin;
anniemao 11:4251b62991ac 79 uint32_t MOSI_Pin;
anniemao 11:4251b62991ac 80 uint32_t MISO_Pin;
anniemao 11:4251b62991ac 81
anniemao 11:4251b62991ac 82 };
anniemao 11:4251b62991ac 83
anniemao 11:4251b62991ac 84 #endif