summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/display.c
blob: bc181cb281da9cedcc52a676b8adb56161785db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdlib.h>
#include <stdint.h>

#include "encoding.h"
#include "platform.h"

#include "eos.h"

#include "board.h"

#include "i2s.h"
#include "net.h"
#include "spi_dev.h"
#include "display.h"

#define BIT_PUT(b, pin)     if (b) GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << (pin)); else GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << (pin));
#define BIT_GET(pin)        ((GPIO_REG(GPIO_INPUT_VAL) & (1 << (pin))) >> (pin))

int eos_disp_select(void) {
    if (eos_i2s_running()) return EOS_ERR_BUSY;
    if (eos_spi_dev() != EOS_SPI_DEV_NET) return EOS_ERR_BUSY;

    eos_net_stop();
    GPIO_REG(GPIO_IOF_EN) &= ~SPI_IOF_MASK;
}

void eos_disp_deselect(void) {
    GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << IOF_SPI1_MOSI);
    GPIO_REG(GPIO_IOF_EN) |= SPI_IOF_MASK;
    eos_net_start(0);
}

void eos_disp_cs_set(void) {
    GPIO_REG(GPIO_OUTPUT_VAL) |= (1 << DISP_PIN_CS);
}

void eos_disp_cs_clear(void) {
    GPIO_REG(GPIO_OUTPUT_VAL) &= ~(1 << DISP_PIN_CS);
}

void eos_disp_write(uint8_t dc, uint8_t data) {
    int i;

    BIT_PUT(dc, IOF_SPI1_MOSI);
    // sleep
    BIT_PUT(1, IOF_SPI1_SCK);
    for (i=0; i<8; i++) {
        // sleep
        BIT_PUT(0, IOF_SPI1_SCK);
        BIT_PUT(data & 0x80, IOF_SPI1_MOSI);
        // sleep
        BIT_PUT(1, IOF_SPI1_SCK);
        data = data << 1;
    }
    // sleep
    BIT_PUT(0, IOF_SPI1_SCK);
}

void eos_disp_read(uint8_t *data) {
    int i;

    *data = 0;
    for (i=0; i<8; i++) {
        // sleep
        BIT_PUT(1, IOF_SPI1_SCK);
        *data = *data << 1;
        *data |= BIT_GET(IOF_SPI1_MISO);
        // sleep
        BIT_PUT(0, IOF_SPI1_SCK);
    }
}