OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [dev/] [display.c] - Blame information for rev 18

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 15 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    display.c
4
//
5
// Project:     CMod S6 System on a Chip, ZipCPU demonstration project
6
//
7
// Purpose:     A device driver for the SPI controlled display.  The primary
8
//              purpose of this "device" is to output SPI instructions, though,
9
//      not to handle screen position or to optimize data set to the display.
10
//
11
// Creator:     Dan Gisselquist, Ph.D.
12
//              Gisselquist Technology, LLC
13
//
14
////////////////////////////////////////////////////////////////////////////////
15
//
16
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
17
//
18
// This program is free software (firmware): you can redistribute it and/or
19
// modify it under the terms of  the GNU General Public License as published
20
// by the Free Software Foundation, either version 3 of the License, or (at
21
// your option) any later version.
22
//
23
// This program is distributed in the hope that it will be useful, but WITHOUT
24
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
25
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
26
// for more details.
27
//
28
// You should have received a copy of the GNU General Public License along
29
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
30
// target there if the PDF file isn't present.)  If not, see
31
// <http://www.gnu.org/licenses/> for a copy.
32
//
33
// License:     GPL, v3, as defined and found on www.gnu.org,
34
//              http://www.gnu.org/licenses/gpl.html
35
//
36
//
37
////////////////////////////////////////////////////////////////////////////////
38
//
39
//
40
#include "board.h"
41
 
42
static void     dispwait(void) {
43
        // Slow us down to the speed the display can handle
44
        // We want to delay about 0x800 clocks.
45
        // Three instructions per loop,
46
        //      LBL:
47
        //              NOOP
48
        //              ADD -1,CTR
49
        //              BNZ LBL
50
        //      40 clocks per instruction, as required by the SPI flash memory
51
        int i = 18;
52
        do {
53
                asm("noop");
54
        } while(i-->0);
55
}
56
 
57
void    dispchar(int ch) {
58
        if (!ch) // Don't display null characters
59
                return;
60
        if (ch&(~0x0ff)) { // Multiple characters to display
61
                int     v = (ch>>24)&0x0ff;
62
                if (v) {
63
                        dispchar(v);
64
                        v = (ch>>16)&0x0ff;
65
                        if (v) {
66
                                dispchar(v);
67
                                v = (ch>> 8)&0x0ff;
68
                                if (v) {
69
                                        dispchar(v);
70
                                        dispchar(ch&0x0ff);
71
                                }
72
                        }
73
                }
74
        } else {
75
                IOSPACE *sys = (IOSPACE *)IOADDR;
76
                // Send the character
77
                for(int i=0; i<8; i++) {
78
                        int gpiov = GPOCLRV(GPO_MOSI|GPO_SCK|GPO_SS);
79
                        if (ch&0x80)
80
                                gpiov |= GPOSETV(GPO_MOSI);
81
                        sys->io_gpio = gpiov;
82
                        dispwait();
83
                        sys->io_gpio = GPOSETV(GPO_SCK);
84
                        dispwait();
85
                        ch<<=1;
86
                }
87
                // Turn off the clock
88
                sys->io_gpio = GPOCLRV(GPO_SCK);
89
                dispwait();
90
                // Then the port
91
                sys->io_gpio = GPOSETV(GPO_SS);
92
                dispwait();
93
        }
94
}
95
 
96
#ifdef  ZIPOS
97
void    displaytask(void) {
98
        while(1) {
99
                int     ch;
100
                read(FILENO_STDIN, &ch, 1);
101
                dispchar(ch);
102
        }
103
}
104
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.