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

Subversion Repositories s6soc

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

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 45 dgisselq
// Copyright (C) 2015-2017, Gisselquist Technology, LLC
17 15 dgisselq
//
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 45 dgisselq
void    dispchar(char ch) {
59 15 dgisselq
        if (!ch) // Don't display null characters
60
                return;
61 45 dgisselq
        int     ich = ch;
62
 
63
        // Send the character
64
        for(int i=0; i<8; i++) {
65
                int gpiov = GPOCLRV(GPO_MOSI|GPO_SCK|GPO_SS);
66
                if (ich&0x80)
67
                        gpiov |= GPOSETV(GPO_MOSI);
68
                _sys->io_gpio = gpiov;
69 15 dgisselq
                dispwait();
70 45 dgisselq
                _sys->io_gpio = GPOSETV(GPO_SCK);
71 15 dgisselq
                dispwait();
72 45 dgisselq
                ich<<=1;
73 15 dgisselq
        }
74 45 dgisselq
 
75
        // Turn off the clock
76
        _sys->io_gpio = GPOCLRV(GPO_SCK);
77
        dispwait();
78
        // Then the port
79
        _sys->io_gpio = GPOSETV(GPO_SS);
80
        dispwait();
81 15 dgisselq
}
82
 
83
#ifdef  ZIPOS
84 21 dgisselq
#include "../zipos/ktraps.h"
85
#include "../zipos/kfildes.h"
86
void    display_task(void) {
87 15 dgisselq
        while(1) {
88 45 dgisselq
                char    ch;
89 15 dgisselq
                read(FILENO_STDIN, &ch, 1);
90
                dispchar(ch);
91
        }
92
}
93
#endif

powered by: WebSVN 2.1.0

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