1
0
mirror of https://github.com/Klagarge/Cursor.git synced 2025-06-26 04:12:31 +00:00

Initial commit

This commit is contained in:
Rémi Heredero
2021-11-24 10:50:51 +01:00
commit c7ba678fbb
961 changed files with 501515 additions and 0 deletions

View File

@ -0,0 +1,159 @@
library Common;
use Common.CommonLib.all;
ARCHITECTURE RTL OF helloWorld IS
constant displaySequenceLength: positive := 97;
type displayDataType is array (1 to displaySequenceLength+1)
of natural;
constant displayData: displayDataType :=(
character'pos(can), -- cancel (clear display)
character'pos(stx), -- start of text (pos 0,0)
character'pos('H'), -- Line 1
character'pos('E'),
character'pos('S'),
character'pos('-'),
character'pos('S'),
character'pos('O'),
character'pos('/'),
character'pos('/'),
character'pos('V'),
character'pos('a'),
character'pos('l'),
character'pos('a'),
character'pos('i'),
character'pos('s'),
character'pos(' '),
character'pos('W'),
character'pos('a'),
character'pos('l'),
character'pos('l'),
character'pos('i'),
character'pos('s'),
character'pos(' '),
character'pos(cr),
character'pos(lf),
character'pos('-'), -- Line 2
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos('-'),
character'pos(cr),
character'pos(lf),
character'pos('F'), -- Line 3
character'pos('P'),
character'pos('G'),
character'pos('A'),
character'pos('-'),
character'pos('E'),
character'pos('B'),
character'pos('S'),
character'pos(' '),
character'pos('L'),
character'pos('C'),
character'pos('D'),
character'pos('-'),
character'pos('E'),
character'pos('x'),
character'pos('t'),
character'pos('e'),
character'pos('n'),
character'pos('s'),
character'pos('i'),
character'pos('o'),
character'pos('n'),
character'pos(cr),
character'pos(lf),
character'pos('L'), -- Line 4
character'pos('C'),
character'pos('D'),
character'pos(','),
character'pos(' '),
character'pos('4'),
character'pos(' '),
character'pos('B'),
character'pos('u'),
character'pos('t'),
character'pos('t'),
character'pos('o'),
character'pos('n'),
character'pos('s'),
character'pos(','),
character'pos(' '),
character'pos('8'),
character'pos(' '),
character'pos('L'),
character'pos('e'),
character'pos('d'),
character'pos('s'),
character'pos(stx), -- start of text (pos 0,0)
character'pos('-')
);
signal sequenceCounter: unsigned(requiredBitNb(displaySequenceLength+1)-1 downto 0);
signal sequenceDone: std_ulogic;
signal buttonDelayed, buttonRising: std_ulogic;
BEGIN
------------------------------------------------------------------------------
-- find button push
delayButton: process(reset, clock)
begin
if reset='1' then
buttonDelayed <= '0';
elsif rising_edge(clock) then
buttonDelayed <= button;
end if;
end process delayButton;
buttonRising <= '1' when (button = '1') and (buttonDelayed = '0')
else '0';
------------------------------------------------------------------------------
-- display sequence counter
countDisplaySequence: process(reset, clock)
begin
if reset='1' then
sequenceCounter <= to_unsigned(1, sequenceCounter'length);
elsif rising_edge(clock) then
if (buttonRising = '1') and (sequenceDone = '1') then
sequenceCounter <= to_unsigned(1, sequenceCounter'length);
elsif busy = '0' then
if sequenceDone = '0' then
sequenceCounter <= sequenceCounter + 1;
end if;
end if;
end if;
end process countDisplaySequence;
sequenceDone <= '1' when sequenceCounter > displaySequenceLength
else '0';
------------------------------------------------------------------------------
-- output control
ascii <= std_ulogic_vector(to_unsigned(
displayData(to_integer(sequenceCounter)), ascii'length
)) when (sequenceCounter > 0)
else (others => '-');
send <= not busy when sequenceDone = '0'
else '0';
END ARCHITECTURE RTL;

View File

@ -0,0 +1,213 @@
library Common;
use Common.CommonLib.all;
ARCHITECTURE Encoder OF lcdCharacterEncoder IS
constant lcdLineBitNb : positive := 6;
constant lcdPageBitNb : positive := 4;
constant lcdColumnBitNb : positive := 8;
type fontDisplayStateType is (
init, idle, readChar, displayColumns
);
signal fontDisplayState : fontDisplayStateType;
signal asciiColumnCounter : unsigned(requiredBitNb(fontColumnNb)-1 downto 0);
signal pixelOffset : unsigned(requiredBitNb(fontColumnNb*fontRowNb-1)-1 downto 0);
signal pageCounter : unsigned(requiredBitNb(lcdPageNb)-1 downto 0);
signal columnCounter : unsigned(requiredBitNb(lcdColumnNb)-1 downto 0);
signal A0 : std_ulogic;
signal pixelPage : std_ulogic_vector(fontRowNb-1 downto 0);
signal pixelColumnHigh : std_ulogic_vector(fontRowNb-1 downto 0);
signal pixelColumnLow : std_ulogic_vector(fontRowNb-1 downto 0);
BEGIN
------------------------------------------------------------------------------
-- diplay FSM
fontDisplaySequencer: process(reset, clock)
begin
if reset = '1' then
fontDisplayState <= init;
elsif rising_edge(clock) then
case fontDisplayState is
when init =>
if lcdBusy = '0' then
fontDisplayState <= idle;
end if;
when idle =>
if asciiSend = '1' then
fontDisplayState <= readChar;
end if;
when readChar =>
fontDisplayState <= displayColumns;
when displayColumns =>
if (asciiColumnCounter = 0) and (lcdBusy = '0') then
fontDisplayState <= idle;
end if;
end case;
end if;
end process fontDisplaySequencer;
asciiBusy <= '0' when fontDisplayState = idle
else '1';
a0_proc: process(reset ,clock)
begin
if reset = '1' then
A0 <= '0';
elsif rising_edge(clock) then
if asciiSend = '1' then
if unsigned(asciiData) < 32 then
A0 <= '0';
else
A0 <= '1';
end if;
end if;
end if;
end process a0_proc;
------------------------------------------------------------------------------
-- ascii column counter
asciiCountColums: process(reset, clock)
begin
if reset = '1' then
asciiColumnCounter <= (others => '0');
elsif rising_edge(clock) then
if asciiColumnCounter = 0 then
if (fontDisplayState = idle) and (asciiSend = '1') then
asciiColumnCounter <= asciiColumnCounter + 1;
end if;
else
if (fontDisplayState = displayColumns) and (lcdBusy = '0') then
if asciiColumnCounter < fontColumnNb then
asciiColumnCounter <= asciiColumnCounter + 1;
else
asciiColumnCounter <= (others => '0');
end if;
end if;
end if;
end if;
end process asciiCountColums;
------------------------------------------------------------------------------
-- page, column counter
counter: process(reset, clock)
begin
if reset = '1' then
pageCounter <= (others => '0');
columnCounter <= (others => '0');
clearDisplay <= '0';
elsif rising_edge(clock) then
clearDisplay <= '0';
if asciiSend = '1' then
case to_integer(unsigned(asciiData)) is
when 2 => -- Start of text (home)
pageCounter <= (others => '0');
columnCounter <= (others => '0');
when 3 => -- End of text (end)
pageCounter <= to_unsigned(lcdPageNb - 1,pageCounter'length);
columnCounter <= to_unsigned(lcdColumnNb - fontColumnNb, columnCounter'length);
when 8 => -- BS (backspace) (column back)
if (columnCounter - fontColumnNb) < 0 then
columnCounter <= (others => '0');
else
columnCounter <= columnCounter - fontColumnNb;
end if;
when 10 => -- LF (linefeed) (next line)
if pageCounter = (lcdPageNb-1) then
pageCounter <= (others => '0');
else
pageCounter <= pageCounter + 1;
end if;
when 11 => -- Vertical Tab (prev line)
if pageCounter = 0 then
pageCounter <= to_unsigned(lcdPageNb - 1,pageCounter'length);
else
pageCounter <= pageCounter - 1;
end if;
when 13 => -- CR (carriage return) (coloumn back)
columnCounter <= (others => '0');
when 24 => -- CAN (cancel) (clear display)
clearDisplay <= '1';
when others =>
if asciiData >= x"20" then -- normal ascii char
columnCounter <= columnCounter + fontColumnNb;
end if;
end case;
end if;
end if;
end process counter;
lcdSend <= '1' when
(fontDisplayState = displayColumns) and
(lcdBusy = '0') and
(asciiColumnCounter > 0)
else '0';
------------------------------------------------------------------------------
-- Ram Data
pixelOffset <= resize(
resize(fontColumnNb-asciiColumnCounter, pixelOffset'length)*fontRowNb,
pixelOffset'length
) when asciiColumnCounter > 0
else (others => '0');
pixelPage <=
pixelData(
to_integer(pixelOffset) + fontRowNb-1 downto
to_integer(pixelOffset) + lcdPageBitNb
) &
std_ulogic_vector(resize(pageCounter,lcdPageBitNb));
pixelColumnHigh <=
pixelData(
to_integer(pixelOffset) + fontRowNb-1 downto
to_integer(pixelOffset) + (lcdColumnBitNb/2)
) &
std_ulogic_vector(columnCounter(
columnCounter'high downto (columnCounter'length/2)
));
pixelColumnLow <=
pixelData(
to_integer(pixelOffset) + fontRowNb-1 downto
to_integer(pixelOffset) + (lcdColumnBitNb/2)
) &
std_ulogic_vector(columnCounter(
(columnCounter'length/2)-1 downto columnCounter'low
));
buildLcdData: process(
A0, pixelData, pixelOffset,
pixelPage, pixelColumnHigh, pixelColumnLow
)
begin
lcdData(lcdData'high) <= A0;
if A0 = '1' then
lcdData(lcdData'high-1 downto 0) <= pixelData(
to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset)
);
elsif pixelOffset >= 40 then
lcdData(lcdData'high-1 downto 0) <= pixelData(
to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset)
);
elsif pixelOffset >= 32 then
lcdData(lcdData'high-1 downto 0) <= pixelPage;
elsif pixelOffset >= 24 then
lcdData(lcdData'high-1 downto 0) <= pixelColumnHigh;
elsif pixelOffset >= 16 then
lcdData(lcdData'high-1 downto 0) <= pixelColumnLow;
else
lcdData(lcdData'high-1 downto 0) <= pixelData(
to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset)
);
end if;
end process buildLcdData;
--lcdData <= A0 & pixelData(to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset)) when (A0 = '1')
-- else A0 & pixelData(to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset)) when (pixelOffset >= 40)
-- else A0 & pixelPage when (pixelOffset >= 32)
-- else A0 & pixelColumnHigh when (pixelOffset >= 24)
-- else A0 & pixelColumnLow when (pixelOffset >= 16)
-- else A0 & pixelData(to_integer(pixelOffset)+fontRowNb-1 downto to_integer(pixelOffset));
END ARCHITECTURE Encoder;

View File

@ -0,0 +1,105 @@
library Common;
use Common.CommonLib.all;
ARCHITECTURE RTL OF lcdInitializer IS
constant initializationSequenceLength: positive := 14;
type initializationDataType is array (1 to initializationSequenceLength+1)
of std_ulogic_vector(lcdData'range);
constant initializationData: initializationDataType :=(
'0' & X"40", -- Display start line 0
'0' & X"A1", -- ADC reverse
'0' & X"C0", -- Normal COM0~COM31
'0' & X"A6", -- Display normal
'0' & X"A2", -- Set bias 1/9 (Duty 1/33)
'0' & X"2F", -- Booster, Regulator and Follower on
'0' & X"F8", -- Set internal Booster to 3x / 4x
'0' & X"00", --
'0' & X"23", -- Contrast set
'0' & X"81", --
'0' & X"1F", --
'0' & X"AC", -- No indicator
'0' & X"00", --
'0' & X"AF", -- Display on
std_ulogic_vector(to_unsigned(0, lcdData'length))
);
constant clearDisplaySequenceLength : positive := 566;--(3+132)*4 + 3; -- (3 commands + 132 columns) * 4 pages + jump back to start
constant clearDisplayDataLength : positive := 6;
type clearDisplayDataType is array (1 to clearDisplayDataLength+1)
of std_ulogic_vector(lcdData'range);
constant clearDisplayData: clearDisplayDataType :=(
-- ind seq
'0' & X"B0", -- 1 Page 0
'0' & X"B1", -- 2 Page 1
'0' & X"B2", -- 3 Page 2
'0' & X"B3", -- 4 Page 3
'0' & X"10", -- 5 Column MSB 0
'0' & X"00", -- 6 Column LSB 0
'1' & X"00" -- 7 Data "empty"
);
signal initSequenceCounter: unsigned(requiredBitNb(initializationSequenceLength+1)-1 downto 0);
signal initSequenceDone: std_ulogic;
signal clearSequenceCounter: unsigned(requiredBitNb(clearDisplaySequenceLength+1)-1 downto 0);
signal clearSequenceDone: std_ulogic;
BEGIN
------------------------------------------------------------------------------
-- initialization sequence counter
buildInitSequence: process(reset, clock)
begin
if reset='1' then
initSequenceCounter <= to_unsigned(1, initSequenceCounter'length);
elsif rising_edge(clock) then
if lcdBusy = '0' then
if initSequenceDone = '0' then
initSequenceCounter <= initSequenceCounter + 1;
end if;
end if;
end if;
end process buildInitSequence;
initSequenceDone <= '1' when initSequenceCounter > initializationSequenceLength
else '0';
------------------------------------------------------------------------------
-- clear sequence counter
buildClearSequence: process(reset, clock)
begin
if reset='1' then
clearSequenceCounter <= to_unsigned(clearDisplaySequenceLength+1, clearSequenceCounter'length);
elsif rising_edge(clock) then
if lcdBusy = '0' then
if clearDisplay = '1' and initSequenceDone = '1' then
clearSequenceCounter <= to_unsigned(1, clearSequenceCounter'length);
elsif clearSequenceDone = '0' then
clearSequenceCounter <= clearSequenceCounter + 1;
end if;
end if;
end if;
end process buildClearSequence;
clearSequenceDone <= '1' when clearSequenceCounter > clearDisplaySequenceLength
else '0';
------------------------------------------------------------------------------
-- data multiplexer
lcdData <= columnData when (initSequenceDone = '1' and clearSequenceDone = '1')
else initializationData(to_integer(initSequenceCounter)) when (initSequenceCounter > 0 and initSequenceDone = '0')
else clearDisplayData(1) when (clearSequenceCounter = 1 or clearSequenceCounter = 564)
else clearDisplayData(2) when (clearSequenceCounter = 137)
else clearDisplayData(3) when (clearSequenceCounter = 273)
else clearDisplayData(4) when (clearSequenceCounter = 409)
else clearDisplayData(5) when (clearSequenceCounter = 2 or clearSequenceCounter = 138 or clearSequenceCounter = 274 or clearSequenceCounter = 410 or clearSequenceCounter = 565)
else clearDisplayData(6) when (clearSequenceCounter = 3 or clearSequenceCounter = 139 or clearSequenceCounter = 275 or clearSequenceCounter = 411 or clearSequenceCounter = 566)
else clearDisplayData(7);
lcdSend <= columnSend when initSequenceDone = '1' and clearSequenceDone = '1'
else not lcdBusy when initSequenceCounter <= initializationSequenceLength
else not lcdBusy when clearSequenceCounter <= clearDisplaySequenceLength
else '0';
columnBusy <= lcdBusy when initSequenceDone = '1' and clearSequenceDone = '1'
else '1';
END ARCHITECTURE RTL;

View File

@ -0,0 +1,143 @@
library Common;
use Common.CommonLib.all;
ARCHITECTURE RTL OF lcdSerializer IS
------------------------------------------------------------------------------
-- The clock-pulse rate of the SCL line can be up to 20 MHz @3.3V
-- The clock frequency is divided by generic value "baudRateDivide"
-- The corresponding "sclEn" is further divided by 2 to generate SCL
--
signal sclCounter: unsigned(requiredBitNb(baudRateDivide-1)-1 downto 0);
signal sclEn: std_ulogic;
signal scl_int: std_ulogic;
------------------------------------------------------------------------------
-- The minimal reset pulse width is 1 us
-- "sclEn" at 40 MHz has to be divided by 40 to generate the 1 us delay
--
constant resetCount : natural := 40;
signal resetCounter: unsigned(requiredBitNb(2*resetCount-1)-1 downto 0);
signal resetDone: std_ulogic;
------------------------------------------------------------------------------
-- Serial data bits have to be stable at the rising edge of SCL
-- Data bits will be updated at the falling edge of SCL
--
-- Data in comprises 9 bits: A0 (as MSB) and 8 row pixels or command bits
-- A0 selects between command data (A0 = 0) and pixel data (A0 = 1)
--
constant pixelsPerColumn : positive := data'length-1;
signal dataSampled : std_ulogic_vector(data'range);
signal chipSelect : std_ulogic;
signal updateData: std_ulogic;
signal dataCounter: unsigned(requiredBitNb(pixelsPerColumn+1)-1 downto 0);
BEGIN
------------------------------------------------------------------------------
-- clock divider for SCL
divideClock: process(reset, clock)
begin
if reset='1' then
scl_int <= '0';
sclCounter <= (others => '0');
elsif rising_edge(clock) then
if sclEn = '1' then
sclCounter <= (others => '0');
scl_int <= not scl_int;
else
sclCounter <= sclCounter + 1;
end if;
end if;
end process divideClock;
sclEn <= '1' when sclCounter = baudRateDivide-1
else '0';
------------------------------------------------------------------------------
-- LCD reset
process(clock,reset)
variable i : natural;
begin
if reset = '1' then
resetCounter <= (others => '0');
elsif rising_edge(clock) then
if sclEn = '1' then
if resetDone = '0' then
resetCounter <= resetCounter + 1;
end if;
end if;
end if;
end process;
resetDone <= '1' when resetCounter >= 2*resetCount-1
else '0';
RST_n <= '1' when resetCounter >= resetCount-1
else '0';
------------------------------------------------------------------------------
-- sample input data
process (reset, clock)
begin
if reset = '1' then
dataSampled <= (others => '0');
elsif rising_edge(clock) then
if send = '1' then
dataSampled <= data;
end if;
end if;
end process;
------------------------------------------------------------------------------
-- A0
A0 <= dataSampled(data'high);
------------------------------------------------------------------------------
-- serialize data
updateData <= sclEn and scl_int;
process (reset, clock)
begin
if reset = '1' then
dataCounter <= (others => '0');
elsif rising_edge(clock) then
if resetDone = '1' then
if dataCounter = 0 then
if send = '1' then
dataCounter <= to_unsigned(pixelsPerColumn+1, dataCounter'length);
end if;
else
if updateData = '1' then
dataCounter <= dataCounter - 1;
end if;
end if;
end if;
end if;
end process;
busy <= '1' when (resetDone = '0') or (dataCounter > 0)
else '0';
chipSelect <= '1' when (dataCounter > 0) and (dataCounter < pixelsPerColumn+1)
else '0';
sampleData: process (reset, clock)
begin
if reset = '1' then
CS_n <= '1';
SCL <= '1';
SI <= '1';
elsif rising_edge(clock) then
if chipSelect = '1' then
CS_n <= '0';
SCL <= scl_int or not(chipSelect);
SI <= dataSampled(to_integer(dataCounter-1));
else
CS_n <= '1';
SCL <= '1';
SI <= '1';
end if;
end if;
end process sampleData;
END ARCHITECTURE RTL;