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

Subversion Repositories s6soc

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

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 21 dgisselq
#include "display.h"
42 15 dgisselq
 
43
static void     dispwait(void) {
44
        // Slow us down to the speed the display can handle
45
        // We want to delay about 0x800 clocks.
46
        // Three instructions per loop,
47
        //      LBL:
48
        //              NOOP
49
        //              ADD -1,CTR
50
        //              BNZ LBL
51
        //      40 clocks per instruction, as required by the SPI flash memory
52
        int i = 18;
53
        do {
54
                asm("noop");
55
        } while(i-->0);
56
}
57
 
58
void    dispchar(int ch) {
59
        if (!ch) // Don't display null characters
60
                return;
61
        if (ch&(~0x0ff)) { // Multiple characters to display
62
                int     v = (ch>>24)&0x0ff;
63
                if (v) {
64
                        dispchar(v);
65
                        v = (ch>>16)&0x0ff;
66
                        if (v) {
67
                                dispchar(v);
68
                                v = (ch>> 8)&0x0ff;
69
                                if (v) {
70
                                        dispchar(v);
71
                                        dispchar(ch&0x0ff);
72
                                }
73
                        }
74
                }
75
        } else {
76
                IOSPACE *sys = (IOSPACE *)IOADDR;
77
                // Send the character
78
                for(int i=0; i<8; i++) {
79
                        int gpiov = GPOCLRV(GPO_MOSI|GPO_SCK|GPO_SS);
80
                        if (ch&0x80)
81
                                gpiov |= GPOSETV(GPO_MOSI);
82
                        sys->io_gpio = gpiov;
83
                        dispwait();
84
                        sys->io_gpio = GPOSETV(GPO_SCK);
85
                        dispwait();
86
                        ch<<=1;
87
                }
88
                // Turn off the clock
89
                sys->io_gpio = GPOCLRV(GPO_SCK);
90
                dispwait();
91
                // Then the port
92
                sys->io_gpio = GPOSETV(GPO_SS);
93
                dispwait();
94
        }
95
}
96
 
97
#ifdef  ZIPOS
98 21 dgisselq
#include "../zipos/ktraps.h"
99
#include "../zipos/kfildes.h"
100
void    display_task(void) {
101 15 dgisselq
        while(1) {
102
                int     ch;
103
                read(FILENO_STDIN, &ch, 1);
104
                dispchar(ch);
105
        }
106
}
107
#endif

powered by: WebSVN 2.1.0

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