www.8devices.com
View unanswered posts | View active topics It is currently 30 Apr 2024, 17:58



Reply to topic  [ 2 posts ] 
 Carambola2 SPI port 
Author Message

Joined: 24 Jan 2014, 07:11
Posts: 2
Hi,

is it possible to use SPI port in mode 3? I would like to use HY28B LCD and it supports only mode 3. I have found only preliminary datasheet for AR9331 yet.

Could anyone help? Maybe some spi mode converter...


24 Jan 2014, 07:16
Profile

Joined: 24 Jan 2014, 07:11
Posts: 2
Issue solved if anyone interested ;) Just add following code into appropriate files:


!ADD file “ath79_spi_platform.h”
struct ath79_spi_platform_data {
.......
unsigned miso_line;
};




!ADD file “spi-ath79.c”
.......
struct ath79_spi {
.......
unsigned miso_line;
.......
}
.......
static u32 ath79_spi_txrx_mode1(struct spi_device *spi, unsigned nsecs,
u32 word, u8 bits)
{
u32 readword = 0;
struct ath79_spi *sp = ath79_spidev_to_sp(spi);
u32 ioc = sp->ioc_base;

/* clock starts at inactive polarity */
for (word <<= (32 - bits); likely(bits); bits--) {
u32 out;

if (word & (1 << 31))
out = ioc | AR71XX_SPI_IOC_DO;
else
out = ioc & ~AR71XX_SPI_IOC_DO;

/* setup MSB (to slave) on trailing edge */
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out | AR71XX_SPI_IOC_CLK);
ath79_spi_delay(sp, nsecs);
readword <<= 1;
readword |= gpio_get_value(sp->miso_line);
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);
ath79_spi_delay(sp, nsecs);

word <<= 1;
}

return readword;
}

static u32 ath79_spi_txrx_mode2(struct spi_device *spi, unsigned nsecs,
u32 word, u8 bits)
{
u32 readword = 0;
struct ath79_spi *sp = ath79_spidev_to_sp(spi);
u32 ioc = sp->ioc_base;

/* clock starts at inactive polarity */
for (word <<= (32 - bits); likely(bits); bits--) {
u32 out;

if (word & (1 << 31))
out = ioc | AR71XX_SPI_IOC_DO;
else
out = ioc & ~AR71XX_SPI_IOC_DO;

/* setup MSB (to slave) on trailing edge */
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);
ath79_spi_delay(sp, nsecs);
readword <<= 1;
readword |= gpio_get_value(sp->miso_line);
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out & ~AR71XX_SPI_IOC_CLK);
ath79_spi_delay(sp, nsecs);
if (bits == 1)
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);

word <<= 1;
}

return readword;
}

static u32 ath79_spi_txrx_mode3(struct spi_device *spi, unsigned nsecs,
u32 word, u8 bits)
{
u32 readword = 0;
struct ath79_spi *sp = ath79_spidev_to_sp(spi);
u32 ioc = sp->ioc_base;

/* clock starts at inactive polarity */
for (word <<= (32 - bits); likely(bits); bits--) {
u32 out;

if (word & (1 << 31))
out = ioc | AR71XX_SPI_IOC_DO;
else
out = ioc & ~AR71XX_SPI_IOC_DO;

/* setup MSB (to slave) on trailing edge */
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out & ~AR71XX_SPI_IOC_CLK);
ath79_spi_delay(sp, nsecs);
readword <<= 1;
readword |= gpio_get_value(sp->miso_line);
ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, out);
ath79_spi_delay(sp, nsecs);

word <<= 1;
}

return readword;
}
.......
sp->miso_line = pdata->miso_line;
.......
sp->bitbang.txrx_word[SPI_MODE_1] = ath79_spi_txrx_mode1;
sp->bitbang.txrx_word[SPI_MODE_2] = ath79_spi_txrx_mode2;
sp->bitbang.txrx_word[SPI_MODE_3] = ath79_spi_txrx_mode3;
.......


10 Feb 2014, 12:18
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron

Protected by Anti-Spam ACP Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.