Driver for external SPI flash memory on Baofeng DM-1801

replace/78451b5223176f00513786762f4e9be51b6622af
Silvano Seva 2020-12-26 19:14:30 +01:00
rodzic d9f6ea31ab
commit aad19cc41c
3 zmienionych plików z 82 dodań i 0 usunięć

Wyświetl plik

@ -255,6 +255,8 @@ gd77_def = def + mk22fn512_def + {'PLATFORM_GD77': ''}
dm1801_src = src + mk22fn512_src + ['platform/targets/DM-1801/platform.c',
'platform/drivers/display/UC1701_GD77.c',
'platform/drivers/keyboard/keyboard_GD77.c',
'platform/drivers/NVM/W25Qx.c',
'platform/drivers/NVM/spiFlash_GDx.c',
'platform/drivers/ADC/ADC0_GDx.c',
'platform/drivers/baseband/rtx_GDx.c']

Wyświetl plik

@ -0,0 +1,74 @@
/***************************************************************************
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <gpio.h>
#include <delays.h>
#include <stdint.h>
#include <hwconfig.h>
/*
* Implementation of external flash SPI interface for GDx devices.
* In these radios the SPI communication has to be managed through software bit
* banging, since there is no SPI peripheral available.
*/
uint8_t spiFlash_SendRecv(uint8_t val)
{
uint8_t data = 0;
for(uint8_t i = 0; i < 8; i++)
{
gpio_clearPin(FLASH_CLK);
delayUs(1);
if((val << i) & 0x80)
{
gpio_setPin(FLASH_SDO);
}
else
{
gpio_clearPin(FLASH_SDO);
}
gpio_setPin(FLASH_CLK);
delayUs(1);
data <<= 1;
data |= (gpio_readPin(FLASH_SDI)) ? 0x01 : 0x00;
}
return data;
}
void spiFlash_init()
{
gpio_setMode(FLASH_CLK, OUTPUT);
gpio_setMode(FLASH_SDO, OUTPUT);
gpio_setMode(FLASH_SDI, INPUT);
gpio_clearPin(FLASH_CLK);
gpio_clearPin(FLASH_SDO);
}
void spiFlash_terminate()
{
gpio_setMode(FLASH_CLK, INPUT);
gpio_setMode(FLASH_SDO, INPUT);
gpio_setMode(FLASH_SDI, INPUT);
}

Wyświetl plik

@ -72,4 +72,10 @@
#define FUNC2_SW GPIOB,1
#define MONI_SW GPIOB,9
/* External flash */
#define FLASH_CS GPIOE,6
#define FLASH_CLK GPIOE,5
#define FLASH_SDO GPIOE,4
#define FLASH_SDI GPIOA,19
#endif