Skip to content

Commit

Permalink
boards/z20x/ez80/20x: Updates
Browse files Browse the repository at this point in the history
boards/z80/ez80/z20x:  Add SPI chip selects for all available SPI definces.
  • Loading branch information
gregory-nutt authored and Ouss4 committed Mar 1, 2020
1 parent a754c25 commit 7d1b35b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
82 changes: 75 additions & 7 deletions boards/z80/ez80/z20x/src/ez80_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,46 @@

void ez80_spidev_initialize(void)
{
#ifdef HAVE_MMCSD
#if defined(HAVE_MMCSD) || defined(HAVE_XPT2046)
uint8_t regval;

/* MMC/SD CS: Port PB2/nSS as output */
uint8_t pins;

/* SPI Devices on the z20x main board:
*
* W25Q32JV CS: Port PB5 as output
*
* SPI Devices on LCD card:
*
* MMC/SD CS: Port PB2/nSS as output
* XPT2046 CS: PB1/T1_IN as output
* SST25VF016 CS: Pulled high
*/

pins = 0;
#ifdef HAVE_SPIFLASH
pins |= EZ80_GPIOD5;
#endif
#ifdef HAVE_XPT2046
pins |= EZ80_GPIOD1;
#endif
#ifdef HAVE_MMCSD
pins |= EZ80_GPIOD2;
#endif

regval = inp(EZ80_PB_DR);
regval |= EZ80_GPIOD2;
regval |= pins;
outp(EZ80_PB_DR, regval);

regval = inp(EZ80_PB_ALT1);
regval &= ~EZ80_GPIOD2;
regval &= ~pins;
outp(EZ80_PB_ALT1, regval);

regval = inp(EZ80_PB_ALT2);
regval &= ~EZ80_GPIOD2;
regval &= ~pins;
outp(EZ80_PB_ALT2, regval);

regval = inp(EZ80_PB_DDR);
regval &= ~EZ80_GPIOD2;
regval &= ~pins;
outp(EZ80_PB_DDR, regval);
#endif
}
Expand Down Expand Up @@ -104,6 +125,52 @@ void ez80_spidev_initialize(void)

void ez80_spiselect(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
{
#ifdef HAVE_SPIFLASH
if (devid == SPIDEV_FLASH(0))
{
uint8_t regval;

/* Set PB5 output */

regval = inp(EZ80_PB_DR);

if (selected)
{
regval &= ~EZ80_GPIOD5;
}
else
{
regval |= EZ80_GPIOD5;
}

outp(EZ80_PB_DR, regval);
return;
}
#endif

#ifdef HAVE_XPT2046
if (devid == SPIDEV_TOUCHSCREEN(0))
{
uint8_t regval;

/* Set PB1/T1_IN output */

regval = inp(EZ80_PB_DR);

if (selected)
{
regval &= ~EZ80_GPIOD1;
}
else
{
regval |= EZ80_GPIOD1;
}

outp(EZ80_PB_DR, regval);
return;
}
#endif

#ifdef HAVE_MMCSD
if (devid == SPIDEV_MMCSD(0))
{
Expand All @@ -123,6 +190,7 @@ void ez80_spiselect(FAR struct spi_dev_s *dev, uint32_t devid, bool selected)
}

outp(EZ80_PB_DR, regval);
return;
}
#endif
}
Expand Down
13 changes: 12 additions & 1 deletion boards/z80/ez80/z20x/src/z20x.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,22 @@

/* Configuration */

#define HAVE_MMCSD 1
#define HAVE_SPIFLASH 1
#define HAVE_MMCSD 1
#define HAVE_XPT2046 1

#if !defined(CONFIG_MTD_W25) || !defined(CONFIG_EZ80_SPI)
# undef HAVE_SPIFLASH
#endif

#if !defined(CONFIG_MMCSD_SPI) || !defined(CONFIG_EZ80_SPI)
# undef HAVE_MMCSD
#endif

#if !defined(CONFIG_INPUT_ADS7843E) || !defined(CONFIG_EZ80_SPI)
# undef HAVE_XPT2046
#endif

/* Helpers for accessing memory mapped registers */

#define ez80_getreg8(a) (*(volatile uint8_t *)(a))
Expand Down

0 comments on commit 7d1b35b

Please sign in to comment.