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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_neoled.vhd] - Blame information for rev 68

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

Line No. Rev Author Line
1 52 zero_gravi
-- #################################################################################################
2
-- # << NEORV32 - Smart LED (WS2811/WS2812) Interface (NEOLED) >>                                  #
3
-- # ********************************************************************************************* #
4 62 zero_gravi
-- # Hardware interface for direct control of "smart LEDs" using an asynchronous serial data       #
5 52 zero_gravi
-- # line. Compatible with the WS2811 and WS2812 LEDs.                                             #
6
-- #                                                                                               #
7 62 zero_gravi
-- # NeoPixel-compatible, RGB (24-bit) and RGBW (32-bit) modes supported (in "parallel")           #
8
-- # (TM) "NeoPixel" is a trademark of Adafruit Industries.                                        #
9 52 zero_gravi
-- #                                                                                               #
10 62 zero_gravi
-- # The interface uses a programmable carrier frequency (800 KHz for the WS2812 LEDs)             #
11 52 zero_gravi
-- # configurable via the control register's clock prescaler bits (ctrl_clksel*_c) and the period  #
12
-- # length configuration bits (ctrl_t_tot_*_c). "high-times" for sending a ZERO or a ONE bit are  #
13
-- # configured using the ctrl_t_0h_*_c and ctrl_t_1h_*_c bits, respectively. 32-bit transfers     #
14
-- # (for RGBW modules) and 24-bit transfers (for RGB modules) are supported via ctrl_mode__c.     #
15
-- #                                                                                               #
16 65 zero_gravi
-- # The device features a TX buffer (FIFO) with <FIFO_DEPTH> entries with configurable interrupt. #
17 52 zero_gravi
-- # ********************************************************************************************* #
18
-- # BSD 3-Clause License                                                                          #
19
-- #                                                                                               #
20
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
21
-- #                                                                                               #
22
-- # Redistribution and use in source and binary forms, with or without modification, are          #
23
-- # permitted provided that the following conditions are met:                                     #
24
-- #                                                                                               #
25
-- # 1. Redistributions of source code must retain the above copyright notice, this list of        #
26
-- #    conditions and the following disclaimer.                                                   #
27
-- #                                                                                               #
28
-- # 2. Redistributions in binary form must reproduce the above copyright notice, this list of     #
29
-- #    conditions and the following disclaimer in the documentation and/or other materials        #
30
-- #    provided with the distribution.                                                            #
31
-- #                                                                                               #
32
-- # 3. Neither the name of the copyright holder nor the names of its contributors may be used to  #
33
-- #    endorse or promote products derived from this software without specific prior written      #
34
-- #    permission.                                                                                #
35
-- #                                                                                               #
36
-- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS   #
37
-- # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF               #
38
-- # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE    #
39
-- # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,     #
40
-- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE #
41
-- # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED    #
42
-- # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     #
43
-- # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED  #
44
-- # OF THE POSSIBILITY OF SUCH DAMAGE.                                                            #
45
-- # ********************************************************************************************* #
46
-- # The NEORV32 Processor - https://github.com/stnolting/neorv32              (c) Stephan Nolting #
47
-- #################################################################################################
48
 
49
library ieee;
50
use ieee.std_logic_1164.all;
51
use ieee.numeric_std.all;
52
 
53
library neorv32;
54
use neorv32.neorv32_package.all;
55
 
56
entity neorv32_neoled is
57 62 zero_gravi
  generic (
58
    FIFO_DEPTH : natural -- TX FIFO depth (1..32k, power of two)
59
  );
60 52 zero_gravi
  port (
61
    -- host access --
62
    clk_i       : in  std_ulogic; -- global clock line
63
    addr_i      : in  std_ulogic_vector(31 downto 0); -- address
64
    rden_i      : in  std_ulogic; -- read enable
65
    wren_i      : in  std_ulogic; -- write enable
66
    data_i      : in  std_ulogic_vector(31 downto 0); -- data in
67
    data_o      : out std_ulogic_vector(31 downto 0); -- data out
68
    ack_o       : out std_ulogic; -- transfer acknowledge
69
    -- clock generator --
70
    clkgen_en_o : out std_ulogic; -- enable clock generator
71
    clkgen_i    : in  std_ulogic_vector(07 downto 0);
72
    -- interrupt --
73
    irq_o       : out std_ulogic; -- interrupt request
74
    -- NEOLED output --
75
    neoled_o    : out std_ulogic -- serial async data line
76
  );
77
end neorv32_neoled;
78
 
79
architecture neorv32_neoled_rtl of neorv32_neoled is
80
 
81
  -- IO space: module base address --
82
  constant hi_abb_c : natural := index_size_f(io_size_c)-1; -- high address boundary bit
83
  constant lo_abb_c : natural := index_size_f(neoled_size_c); -- low address boundary bit
84
 
85
  -- access control --
86
  signal acc_en : std_ulogic; -- module access enable
87
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
88
  signal wren   : std_ulogic; -- word write enable
89
  signal rden   : std_ulogic; -- read enable
90
 
91
  -- Control register bits --
92 68 zero_gravi
  constant ctrl_en_c       : natural :=  0; -- r/w: module enable
93 65 zero_gravi
  constant ctrl_mode_c     : natural :=  1; -- r/w: 0 = 24-bit RGB mode, 1 = 32-bit RGBW mode
94
  constant ctrl_strobe_c   : natural :=  2; -- r/w: 0 = send normal data, 1 = send LED strobe command (RESET) on data write
95 62 zero_gravi
  --
96 65 zero_gravi
  constant ctrl_clksel0_c  : natural :=  3; -- r/w: prescaler select bit 0
97
  constant ctrl_clksel1_c  : natural :=  4; -- r/w: prescaler select bit 1
98
  constant ctrl_clksel2_c  : natural :=  5; -- r/w: prescaler select bit 2
99 52 zero_gravi
  --
100 65 zero_gravi
  constant ctrl_bufs_0_c   : natural :=  6; -- r/-: log2(FIFO_DEPTH) bit 0
101
  constant ctrl_bufs_1_c   : natural :=  7; -- r/-: log2(FIFO_DEPTH) bit 1
102
  constant ctrl_bufs_2_c   : natural :=  8; -- r/-: log2(FIFO_DEPTH) bit 2
103
  constant ctrl_bufs_3_c   : natural :=  9; -- r/-: log2(FIFO_DEPTH) bit 3
104 52 zero_gravi
  --
105 65 zero_gravi
  constant ctrl_t_tot_0_c  : natural := 10; -- r/w: pulse-clock ticks per total period bit 0
106
  constant ctrl_t_tot_1_c  : natural := 11; -- r/w: pulse-clock ticks per total period bit 1
107
  constant ctrl_t_tot_2_c  : natural := 12; -- r/w: pulse-clock ticks per total period bit 2
108
  constant ctrl_t_tot_3_c  : natural := 13; -- r/w: pulse-clock ticks per total period bit 3
109
  constant ctrl_t_tot_4_c  : natural := 14; -- r/w: pulse-clock ticks per total period bit 4
110 52 zero_gravi
  --
111 65 zero_gravi
  constant ctrl_t_0h_0_c   : natural := 15; -- r/w: pulse-clock ticks per ZERO high-time bit 0
112
  constant ctrl_t_0h_1_c   : natural := 16; -- r/w: pulse-clock ticks per ZERO high-time bit 1
113
  constant ctrl_t_0h_2_c   : natural := 17; -- r/w: pulse-clock ticks per ZERO high-time bit 2
114
  constant ctrl_t_0h_3_c   : natural := 18; -- r/w: pulse-clock ticks per ZERO high-time bit 3
115
  constant ctrl_t_0h_4_c   : natural := 19; -- r/w: pulse-clock ticks per ZERO high-time bit 4
116 52 zero_gravi
  --
117 65 zero_gravi
  constant ctrl_t_1h_0_c   : natural := 20; -- r/w: pulse-clock ticks per ONE high-time bit 0
118
  constant ctrl_t_1h_1_c   : natural := 21; -- r/w: pulse-clock ticks per ONE high-time bit 1
119
  constant ctrl_t_1h_2_c   : natural := 22; -- r/w: pulse-clock ticks per ONE high-time bit 2
120
  constant ctrl_t_1h_3_c   : natural := 23; -- r/w: pulse-clock ticks per ONE high-time bit 3
121
  constant ctrl_t_1h_4_c   : natural := 24; -- r/w: pulse-clock ticks per ONE high-time bit 4
122 52 zero_gravi
  --
123 65 zero_gravi
  constant ctrl_irq_conf_c : natural := 27; -- r/w: interrupt config: 1=IRQ when buffer is empty, 0=IRQ when buffer is half-empty
124
  constant ctrl_tx_empty_c : natural := 28; -- r/-: TX FIFO is empty
125
  constant ctrl_tx_half_c  : natural := 29; -- r/-: TX FIFO is at least half-full
126
  constant ctrl_tx_full_c  : natural := 30; -- r/-: TX FIFO is full
127
  constant ctrl_tx_busy_c  : natural := 31; -- r/-: serial TX engine busy when set
128 52 zero_gravi
 
129
  -- control register --
130
  type ctrl_t is record
131
    enable   : std_ulogic;
132
    mode     : std_ulogic;
133 62 zero_gravi
    strobe   : std_ulogic;
134 52 zero_gravi
    clk_prsc : std_ulogic_vector(2 downto 0);
135 65 zero_gravi
    irq_conf : std_ulogic;
136 52 zero_gravi
    -- pulse config --
137
    t_total  : std_ulogic_vector(4 downto 0);
138
    t0_high  : std_ulogic_vector(4 downto 0);
139
    t1_high  : std_ulogic_vector(4 downto 0);
140
  end record;
141
  signal ctrl : ctrl_t;
142
 
143
  -- transmission buffer --
144
  type tx_buffer_t is record
145 65 zero_gravi
    we    : std_ulogic; -- write enable
146
    re    : std_ulogic; -- read enable
147
    clear : std_ulogic; -- sync reset, high-active
148
    wdata : std_ulogic_vector(31+2 downto 0); -- write data (excluding mode)
149
    rdata : std_ulogic_vector(31+2 downto 0); -- read data (including mode)
150
    avail : std_ulogic; -- data available?
151
    free  : std_ulogic; -- free entry available?
152
    half  : std_ulogic; -- half full
153 52 zero_gravi
  end record;
154
  signal tx_buffer : tx_buffer_t;
155
 
156 68 zero_gravi
  -- interrupt generator --
157
  type irq_t is record
158
    pending : std_ulogic; -- pending interrupt request
159
    set     : std_ulogic;
160
    clr     : std_ulogic;
161
  end record;
162
  signal irq : irq_t;
163
 
164 52 zero_gravi
  -- serial transmission engine --
165 62 zero_gravi
  type serial_state_t is (S_IDLE, S_INIT, S_GETBIT, S_PULSE, S_STROBE);
166 52 zero_gravi
  type serial_t is record
167
    -- state control --
168 62 zero_gravi
    state      : serial_state_t;
169
    mode       : std_ulogic;
170 68 zero_gravi
    done       : std_ulogic;
171 62 zero_gravi
    busy       : std_ulogic;
172
    bit_cnt    : std_ulogic_vector(5 downto 0);
173 52 zero_gravi
    -- shift register --
174 62 zero_gravi
    sreg       : std_ulogic_vector(31 downto 0);
175
    next_bit   : std_ulogic; -- next bit to send
176 52 zero_gravi
    -- pulse generator --
177 62 zero_gravi
    pulse_clk  : std_ulogic; -- pulse cycle "clock"
178
    pulse_cnt  : std_ulogic_vector(4 downto 0);
179
    t_high     : std_ulogic_vector(4 downto 0);
180
    strobe_cnt : std_ulogic_vector(6 downto 0);
181
    tx_out     : std_ulogic;
182 52 zero_gravi
  end record;
183
  signal serial : serial_t;
184
 
185
begin
186
 
187
  -- Sanity Checks --------------------------------------------------------------------------
188
  -- -------------------------------------------------------------------------------------------
189 62 zero_gravi
  assert not ((is_power_of_two_f(FIFO_DEPTH) = false) or (FIFO_DEPTH < 1) or (FIFO_DEPTH > 32768)) report
190
  "NEORV32 PROCESSOR CONFIG ERROR! Invalid <NEOLED.FIFO_DEPTH> buffer size configuration (1..32k)!" severity error;
191 52 zero_gravi
 
192
 
193
  -- Access Control -------------------------------------------------------------------------
194
  -- -------------------------------------------------------------------------------------------
195
  acc_en <= '1' when (addr_i(hi_abb_c downto lo_abb_c) = neoled_base_c(hi_abb_c downto lo_abb_c)) else '0';
196
  addr   <= neoled_base_c(31 downto lo_abb_c) & addr_i(lo_abb_c-1 downto 2) & "00"; -- word aligned
197
  wren   <= acc_en and wren_i;
198
  rden   <= acc_en and rden_i;
199
 
200
 
201
  -- Read/Write Access ----------------------------------------------------------------------
202
  -- -------------------------------------------------------------------------------------------
203
  rw_access: process(clk_i)
204
  begin
205
    if rising_edge(clk_i) then
206
      -- access acknowledge --
207
      ack_o <= wren or rden;
208
 
209 62 zero_gravi
      -- write access: control register --
210
      if (wren = '1') and (addr = neoled_ctrl_addr_c) then
211 68 zero_gravi
        ctrl.enable   <= data_i(ctrl_en_c);
212 62 zero_gravi
        ctrl.mode     <= data_i(ctrl_mode_c);
213
        ctrl.strobe   <= data_i(ctrl_strobe_c);
214
        ctrl.clk_prsc <= data_i(ctrl_clksel2_c downto ctrl_clksel0_c);
215 65 zero_gravi
        ctrl.irq_conf <= data_i(ctrl_irq_conf_c);
216 62 zero_gravi
        ctrl.t_total  <= data_i(ctrl_t_tot_4_c downto ctrl_t_tot_0_c);
217
        ctrl.t0_high  <= data_i(ctrl_t_0h_4_c  downto ctrl_t_0h_0_c);
218
        ctrl.t1_high  <= data_i(ctrl_t_1h_4_c  downto ctrl_t_1h_0_c);
219 52 zero_gravi
      end if;
220
 
221
      -- read access: control register --
222
      data_o <= (others => '0');
223 62 zero_gravi
      if (rden = '1') then -- and (addr = neoled_ctrl_addr_c) then
224 68 zero_gravi
        data_o(ctrl_en_c)                            <= ctrl.enable;
225 52 zero_gravi
        data_o(ctrl_mode_c)                          <= ctrl.mode;
226 62 zero_gravi
        data_o(ctrl_strobe_c)                        <= ctrl.strobe;
227 52 zero_gravi
        data_o(ctrl_clksel2_c downto ctrl_clksel0_c) <= ctrl.clk_prsc;
228 65 zero_gravi
        data_o(ctrl_irq_conf_c)                      <= ctrl.irq_conf or bool_to_ulogic_f(boolean(FIFO_DEPTH = 1)); -- tie to one if FIFO_DEPTH is 1
229 62 zero_gravi
        data_o(ctrl_bufs_3_c  downto ctrl_bufs_0_c)  <= std_ulogic_vector(to_unsigned(index_size_f(FIFO_DEPTH), 4));
230 52 zero_gravi
        data_o(ctrl_t_tot_4_c downto ctrl_t_tot_0_c) <= ctrl.t_total;
231
        data_o(ctrl_t_0h_4_c  downto ctrl_t_0h_0_c)  <= ctrl.t0_high;
232
        data_o(ctrl_t_1h_4_c  downto ctrl_t_1h_0_c)  <= ctrl.t1_high;
233 62 zero_gravi
        --
234
        data_o(ctrl_tx_empty_c)                      <= not tx_buffer.avail;
235
        data_o(ctrl_tx_half_c)                       <= tx_buffer.half;
236
        data_o(ctrl_tx_full_c)                       <= not tx_buffer.free;
237
        data_o(ctrl_tx_busy_c)                       <= serial.busy;
238 52 zero_gravi
      end if;
239
    end if;
240
  end process rw_access;
241
 
242
  -- enable external clock generator --
243
  clkgen_en_o <= ctrl.enable;
244
 
245 62 zero_gravi
  -- FIFO write access --
246
  tx_buffer.we    <= '1' when (wren = '1') and (addr = neoled_data_addr_c) else '0';
247
  tx_buffer.wdata <= ctrl.strobe & ctrl.mode & data_i;
248
  tx_buffer.clear <= not ctrl.enable;
249 52 zero_gravi
 
250 62 zero_gravi
 
251
  -- IRQ Generator --------------------------------------------------------------------------
252
  -- -------------------------------------------------------------------------------------------
253 68 zero_gravi
  irq_select: process(ctrl, tx_buffer)
254
  begin
255
    if (FIFO_DEPTH = 1) then
256
      irq.set <= tx_buffer.free; -- fire IRQ if FIFO is empty
257
    else
258
      if (ctrl.irq_conf = '0') then -- fire IRQ if FIFO is less than half-full
259
        irq.set <= not tx_buffer.half;
260
      else -- fire IRQ if FIFO is empty
261
        irq.set <= tx_buffer.free;
262
      end if;
263
    end if;
264
  end process irq_select;
265
 
266
  -- Interrupt Arbiter --
267 62 zero_gravi
  irq_generator: process(clk_i)
268
  begin
269
    if rising_edge(clk_i) then
270 65 zero_gravi
      if (ctrl.enable = '0') then
271 68 zero_gravi
        irq.pending <= '0';
272 65 zero_gravi
      else
273 68 zero_gravi
        if (irq.set = '1') and (serial.done = '1') then -- evaluate IRQ condition when transmitter is done again
274
          irq.pending <= '1';
275
        elsif (irq.clr = '1') then
276
          irq.pending <= '0';
277 65 zero_gravi
        end if;
278
      end if;
279 62 zero_gravi
    end if;
280
  end process irq_generator;
281
 
282 68 zero_gravi
  -- IRQ request to CPU --
283
  irq_o <= irq.pending;
284 62 zero_gravi
 
285 68 zero_gravi
  -- IRQ acknowledge --
286
  irq.clr <= '1' when (wren = '1') else '0'; -- write data or control register
287
 
288
 
289 52 zero_gravi
  -- TX Buffer (FIFO) -----------------------------------------------------------------------
290
  -- -------------------------------------------------------------------------------------------
291 61 zero_gravi
  tx_data_fifo: neorv32_fifo
292
  generic map (
293 62 zero_gravi
    FIFO_DEPTH => FIFO_DEPTH, -- number of fifo entries; has to be a power of two; min 1
294
    FIFO_WIDTH => 32+2,       -- size of data elements in fifo
295
    FIFO_RSYNC => true,       -- sync read
296
    FIFO_SAFE  => true        -- safe access
297 61 zero_gravi
  )
298
  port map (
299
    -- control --
300
    clk_i   => clk_i,           -- clock, rising edge
301
    rstn_i  => '1',             -- async reset, low-active
302 62 zero_gravi
    clear_i => tx_buffer.clear, -- sync reset, high-active
303 65 zero_gravi
    level_o => open,            -- fill level
304
    half_o  => tx_buffer.half,  -- FIFO is at least half full
305 61 zero_gravi
    -- write port --
306 62 zero_gravi
    wdata_i => tx_buffer.wdata, -- write data
307 61 zero_gravi
    we_i    => tx_buffer.we,    -- write enable
308
    free_o  => tx_buffer.free,  -- at least one entry is free when set
309
    -- read port --
310
    re_i    => tx_buffer.re,    -- read enable
311
    rdata_o => tx_buffer.rdata, -- read data
312
    avail_o => tx_buffer.avail  -- data available when set
313
  );
314 52 zero_gravi
 
315 65 zero_gravi
  -- try to get new TX data --
316
  tx_buffer.re <= '1' when (serial.state = S_IDLE) else '0';
317 52 zero_gravi
 
318
 
319
  -- Serial TX Engine -----------------------------------------------------------------------
320
  -- -------------------------------------------------------------------------------------------
321
  serial_engine: process(clk_i)
322
  begin
323
    if rising_edge(clk_i) then
324 62 zero_gravi
      -- clock generator --
325 52 zero_gravi
      serial.pulse_clk <= clkgen_i(to_integer(unsigned(ctrl.clk_prsc)));
326
 
327 68 zero_gravi
      -- defaults --
328
      serial.done <= '0';
329
 
330 62 zero_gravi
      -- FSM --
331 52 zero_gravi
      if (ctrl.enable = '0') then -- disabled
332 62 zero_gravi
        serial.state <= S_IDLE;
333 52 zero_gravi
      else
334
        case serial.state is
335
 
336
          when S_IDLE => -- waiting for new TX data
337
          -- ------------------------------------------------------------
338 62 zero_gravi
            serial.tx_out     <= '0';
339
            serial.pulse_cnt  <= (others => '0');
340
            serial.strobe_cnt <= (others => '0');
341 52 zero_gravi
            if (tx_buffer.avail = '1') then
342
              serial.state <= S_INIT;
343
            end if;
344
 
345
          when S_INIT => -- initialize TX shift engine
346
          -- ------------------------------------------------------------
347 62 zero_gravi
            if (tx_buffer.rdata(33) = '0') then -- send data
348
              if (tx_buffer.rdata(32) = '0') then -- mode = "RGB" 
349
                serial.mode    <= '0';
350
                serial.bit_cnt <= "011000"; -- total number of bits to send: 3x8=24
351
              else -- mode = "RGBW"
352
                serial.mode    <= '1';
353
                serial.bit_cnt <= "100000"; -- total number of bits to send: 4x8=32
354
              end if;
355
              serial.sreg  <= tx_buffer.rdata(31 downto 00);
356
              serial.state <= S_GETBIT;
357
            else -- send RESET command
358
              serial.state <= S_STROBE;
359 52 zero_gravi
            end if;
360
 
361
          when S_GETBIT => -- get next TX bit
362
          -- ------------------------------------------------------------
363
            serial.sreg      <= serial.sreg(serial.sreg'left-1 downto 0) & '0'; -- shift left by one position (MSB-first)
364
            serial.bit_cnt   <= std_ulogic_vector(unsigned(serial.bit_cnt) - 1);
365
            serial.pulse_cnt <= (others => '0');
366 65 zero_gravi
            if (serial.next_bit = '0') then -- send zero-bit
367
              serial.t_high <= ctrl.t0_high;
368
            else -- send one-bit
369
              serial.t_high <= ctrl.t1_high;
370
            end if;
371 52 zero_gravi
            if (serial.bit_cnt = "000000") then -- all done?
372 65 zero_gravi
              serial.tx_out <= '0';
373 68 zero_gravi
              serial.done   <= '1'; -- done sending data
374 65 zero_gravi
              serial.state  <= S_IDLE;
375
            else -- send current data MSB
376
              serial.tx_out <= '1';
377 52 zero_gravi
              serial.state  <= S_PULSE; -- transmit single pulse
378
            end if;
379
 
380
          when S_PULSE => -- send pulse with specific duty cycle
381
          -- ------------------------------------------------------------
382
            -- total pulse length = ctrl.t_total
383
            -- pulse high time    = serial.t_high
384
            if (serial.pulse_clk = '1') then
385
              serial.pulse_cnt <= std_ulogic_vector(unsigned(serial.pulse_cnt) + 1);
386
              -- T_high reached? --
387
              if (serial.pulse_cnt = serial.t_high) then
388 62 zero_gravi
                serial.tx_out <= '0';
389 52 zero_gravi
              end if;
390
              -- T_total reached? --
391
              if (serial.pulse_cnt = ctrl.t_total) then
392
                serial.state <= S_GETBIT; -- get next bit to send
393
              end if;
394
            end if;
395
 
396 62 zero_gravi
          when S_STROBE => -- strobe LED data ("RESET" command)
397
          -- ------------------------------------------------------------
398
            -- wait for 127 * ctrl.t_total to _ensure_ RESET
399
            if (serial.pulse_clk = '1') then
400
              -- T_total reached? --
401
              if (serial.pulse_cnt = ctrl.t_total) then
402
                serial.pulse_cnt  <= (others => '0');
403
                serial.strobe_cnt <= std_ulogic_vector(unsigned(serial.strobe_cnt) + 1);
404
              else
405
                serial.pulse_cnt <= std_ulogic_vector(unsigned(serial.pulse_cnt) + 1);
406
              end if;
407
            end if;
408
            -- number of LOW periods reached for RESET? --
409
            if (and_reduce_f(serial.strobe_cnt) = '1') then
410 68 zero_gravi
              serial.done  <= '1'; -- done sending RESET
411 62 zero_gravi
              serial.state <= S_IDLE;
412
            end if;
413
 
414 52 zero_gravi
          when others => -- undefined
415
          -- ------------------------------------------------------------
416
            serial.state <= S_IDLE;
417
 
418
        end case;
419
      end if;
420 62 zero_gravi
      -- serial data tx_out --
421
      neoled_o <= serial.tx_out and ctrl.enable;
422 52 zero_gravi
    end if;
423
  end process serial_engine;
424
 
425
  -- SREG's TX data: bit 23 for RGB mode (24-bit), bit 31 for RGBW mode (32-bit) --
426
  serial.next_bit <= serial.sreg(23) when (serial.mode = '0') else serial.sreg(31);
427
 
428
  -- TX engine status --
429 65 zero_gravi
  serial.busy <= '0' when (serial.state = S_IDLE) else '1';
430 52 zero_gravi
 
431
 
432
end neorv32_neoled_rtl;

powered by: WebSVN 2.1.0

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