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.
Dependents: Threaded_LoRa_Modem
RHHardwareSPI.cpp
00001 // RHHardwareSPI.h 00002 // Author: Mike McCauley (mikem@airspayce.com) 00003 // Copyright (C) 2011 Mike McCauley 00004 // Contributed by Joanna Rutkowska 00005 // $Id: RHHardwareSPI.cpp,v 1.12 2015/07/01 00:46:05 mikem Exp $ 00006 00007 #include <RHHardwareSPI.h> 00008 00009 // Declare a single default instance of the hardware SPI interface class 00010 RHHardwareSPI hardware_spi; 00011 00012 00013 // grab config from mbed_app.json 00014 SPI _SPI(RADIO_MOSI, RADIO_MISO, RADIO_SCLK); 00015 00016 #define REVERSE_BITS(byte) (((reverse_lookup[(byte & 0x0F)]) << 4) + reverse_lookup[((byte & 0xF0) >> 4)]) 00017 00018 static const uint8_t reverse_lookup[] = { 0, 8, 4, 12, 2, 10, 6, 14,1, 9, 5, 13,3, 11, 7, 15 }; 00019 00020 00021 // Arduino Due has default SPI pins on central SPI headers, and not on 10, 11, 12, 13 00022 // as per otherArduinos 00023 // http://21stdigitalhome.blogspot.com.au/2013/02/arduino-due-hardware-SPI.html 00024 #if defined (__arm__) && !defined(CORE_TEENSY) 00025 // Arduino Due in 1.5.5 has no definitions for SPI dividers 00026 // SPI clock divider is based on MCK of 84MHz 00027 #define SPI_CLOCK_DIV16 (VARIANT_MCK/84000000) // 1MHz 00028 #define SPI_CLOCK_DIV8 (VARIANT_MCK/42000000) // 2MHz 00029 #define SPI_CLOCK_DIV4 (VARIANT_MCK/21000000) // 4MHz 00030 #define SPI_CLOCK_DIV2 (VARIANT_MCK/10500000) // 8MHz 00031 #define SPI_CLOCK_DIV1 (VARIANT_MCK/5250000) // 16MHz 00032 00033 RHHardwareSPI::RHHardwareSPI(Frequency frequency, BitOrder bitOrder, DataMode dataMode) 00034 : 00035 RHGenericSPI(frequency, bitOrder, dataMode) 00036 { 00037 } 00038 00039 uint8_t RHHardwareSPI::transfer(uint8_t data) 00040 { 00041 if (_bitOrder == BitOrderLSBFirst) 00042 data = REVERSE_BITS(data); 00043 00044 return _SPI.write(data); 00045 } 00046 00047 void RHHardwareSPI::attachInterrupt() 00048 { 00049 // figure out how to do an interrupt thingy here 00050 } 00051 00052 void RHHardwareSPI::detachInterrupt() 00053 { 00054 // figure out how to do an interrupt thingy here too 00055 } 00056 00057 void RHHardwareSPI::begin() 00058 { 00059 00060 uint8_t dataMode; 00061 if (_dataMode == DataMode0) 00062 dataMode = 0; 00063 else if (_dataMode == DataMode1) 00064 dataMode = 1; 00065 else if (_dataMode == DataMode2) 00066 dataMode = 2; 00067 else if (_dataMode == DataMode3) 00068 dataMode = 3; 00069 // printf("mode %d\n", dataMode); 00070 _SPI.format(8, dataMode); 00071 00072 int frequency; 00073 switch (_frequency) 00074 { 00075 case Frequency1MHz: 00076 default: 00077 frequency = 1000000; 00078 break; 00079 00080 case Frequency2MHz: 00081 frequency = 2000000; 00082 break; 00083 00084 case Frequency4MHz: 00085 frequency = 4000000; 00086 break; 00087 00088 case Frequency8MHz: 00089 frequency = 8000000; 00090 break; 00091 00092 case Frequency16MHz: 00093 frequency = 16000000; 00094 break; 00095 } 00096 // printf("@%dHz\n",frequency); 00097 _SPI.frequency(frequency); 00098 00099 } 00100 00101 void RHHardwareSPI::end() 00102 { 00103 } 00104 00105 #endif 00106
Generated on Thu Jul 14 2022 12:14:49 by
1.7.2