Driver for AT24Cx external EEPROM present on GDx devices

replace/a8e720b0081182c4894ef8de2af668843fee73c1
Silvano Seva 2020-12-28 18:31:20 +01:00
rodzic b393cdad8d
commit ff7216e9cd
5 zmienionych plików z 181 dodań i 0 usunięć

Wyświetl plik

@ -257,6 +257,7 @@ 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/AT24Cx_GDx.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,51 @@
/***************************************************************************
* 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/> *
***************************************************************************/
#ifndef AT24Cx_H
#define AT24Cx_H
#include <stdint.h>
#include <sys/types.h>
/**
* Driver for ATMEL AT24Cx family of I2C EEPROM devices, used as external non
* volatile memory on various radios to store global settings and contact data.
*/
/**
* Initialise driver for external EEPROM.
*/
void AT24Cx_init();
/**
* Terminate driver for external EEPROM.
*/
void AT24Cx_terminate();
/**
* Read data from EEPROM memory.
*
* @param addr: start address for read operation.
* @param buf: pointer to a buffer where data is written to.
* @param len: number of bytes to read.
*/
void AT24Cx_readData(uint32_t addr, void *buf, size_t len);
#endif /* AT24Cx_H */

Wyświetl plik

@ -0,0 +1,62 @@
/***************************************************************************
* 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 "AT24Cx.h"
#include <I2C0.h>
#include <gpio.h>
#include <delays.h>
#include <stdint.h>
#include <hwconfig.h>
static const uint8_t devAddr = 0xA0; /* EEPROM I2C address */
void AT24Cx_init()
{
gpio_setMode(I2C_SDA, OPEN_DRAIN);
gpio_setMode(I2C_SCL, OPEN_DRAIN);
gpio_setAlternateFunction(I2C_SDA, 3);
gpio_setAlternateFunction(I2C_SCL, 3);
i2c0_init();
}
void AT24Cx_terminate()
{
i2c0_terminate();
gpio_setMode(I2C_SDA, INPUT);
gpio_setMode(I2C_SCL, INPUT);
}
void AT24Cx_readData(uint32_t addr, void* buf, size_t len)
{
uint16_t a = __builtin_bswap16((uint16_t) addr);
/*
* On GDx devices the I2C bus is shared between the EEPROM and the AT1846S,
* so we have to acquire exclusive ownership before exchanging data
*/
i2c0_lockDeviceBlocking();
i2c0_write(devAddr, &a, 2, false);
delayUs(10);
i2c0_read(devAddr, buf, len);
i2c0_releaseDevice();
}

Wyświetl plik

@ -78,4 +78,8 @@
#define FLASH_SDO GPIOE,4
#define FLASH_SDI GPIOA,19
/* I2C for EEPROM and AT1846S */
#define I2C_SDA GPIOE,25
#define I2C_SCL GPIOE,24
#endif

Wyświetl plik

@ -0,0 +1,63 @@
/***************************************************************************
* 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 <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include <AT24Cx.h>
void printChunk(void *chunk)
{
uint8_t *ptr = ((uint8_t *) chunk);
for(size_t i = 0; i < 16; i++) printf("%02x ", ptr[i]);
for(size_t i = 0; i < 16; i++)
{
if((ptr[i] > 0x22) && (ptr[i] < 0x7f))
{
printf("%c", ptr[i]);
}
else
{
printf(".");
}
}
}
int main()
{
AT24Cx_init();
while(1)
{
getchar();
for(uint16_t addr = 0; addr < 0x10000; addr += 16)
{
uint8_t buf[16];
AT24Cx_readData(addr, buf, 16);
printf("\r\n%lx: ", addr);
printChunk(buf);
puts("\r");
}
}
return 0;
}