123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #include <stdint.h>
- #include <stdbool.h>
- #include "platform.h"
- #if defined( USE_SX1276_RADIO )
- #include "spi.h"
- #include "sx1276-Hal.h"
- #define RESET_IOPORT GPIOB
- #define RESET_PIN GPIO_Pin_11
- #define DIO0_IOPORT GPIOG
- #define DIO0_PIN GPIO_Pin_6
- void SX1276InitIo( void )
- {
- RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOB, ENABLE);
-
- GPIO_InitTypeDef GPIO_InitStruct;
- GPIO_InitStruct.GPIO_Pin = RESET_PIN;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
- GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
- GPIO_Init(RESET_IOPORT, &GPIO_InitStruct);
-
- RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOG, ENABLE);
- GPIO_InitStruct.GPIO_Pin = DIO0_PIN;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_NOPULL;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(DIO0_IOPORT, &GPIO_InitStruct);
- spi_config();
- }
- void SX1276SetReset( uint8_t state )
- {
- GPIO_WriteBit( RESET_IOPORT, RESET_PIN,(BitAction) state );
- }
- void SX1276Write( uint8_t addr, uint8_t data )
- {
- SX1276WriteBuffer( addr, &data, 1 );
- }
- void SX1276Read( uint8_t addr, uint8_t *data )
- {
- SX1276ReadBuffer( addr, data, 1 );
- }
- void SX1276WriteBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
- {
- uint8_t i;
-
- SpiNSSEnable(0);
- SPI2_ReadWriteByte( addr | 0x80 );
- for( i = 0; i < size; i++ )
- {
- SPI2_ReadWriteByte( buffer[i] );
- }
-
- SpiNSSEnable(1);
- }
- void SX1276ReadBuffer( uint8_t addr, uint8_t *buffer, uint8_t size )
- {
- uint8_t i;
-
- SpiNSSEnable(0);
- SPI2_ReadWriteByte( addr & 0x7F );
- for( i = 0; i < size; i++ )
- {
- buffer[i] = SPI2_ReadWriteByte( 0 );
- }
-
- SpiNSSEnable( 1 );
- }
- void SX1276WriteFifo( uint8_t *buffer, uint8_t size )
- {
- SX1276WriteBuffer( 0, buffer, size );
- }
- void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
- {
- SX1276ReadBuffer( 0, buffer, size );
- }
- inline uint8_t SX1276ReadDio0( void )
- {
- return GPIO_ReadInputDataBit( DIO0_IOPORT, DIO0_PIN );
- }
- inline uint8_t SX1276ReadDio1( void )
- {
- return 1;
- }
- inline uint8_t SX1276ReadDio2( void )
- {
- return 1;
- }
- inline uint8_t SX1276ReadDio3( void )
- {
- return 1;
- }
- inline uint8_t SX1276ReadDio4( void )
- {
- return 1;
- }
- inline uint8_t SX1276ReadDio5( void )
- {
- return 1;
- }
- inline void SX1276WriteRxTx( uint8_t txEnable )
- {
- }
- #endif
|