parts: Updated to name their IRQs
[simavr] / examples / parts / hc595.h
1 /*
2         hc595.h
3
4         This defines a sample for a very simple "peripheral" 
5         that can talk to an AVR core.
6         It is in fact a bit more involved than strictly necessary,
7         but is made to demonstrante a few useful features that are
8         easy to use.
9         
10         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
11
12         This file is part of simavr.
13
14         simavr is free software: you can redistribute it and/or modify
15         it under the terms of the GNU General Public License as published by
16         the Free Software Foundation, either version 3 of the License, or
17         (at your option) any later version.
18
19         simavr is distributed in the hope that it will be useful,
20         but WITHOUT ANY WARRANTY; without even the implied warranty of
21         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22         GNU General Public License for more details.
23
24         You should have received a copy of the GNU General Public License
25         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
26  */
27
28 #ifndef __HC595_H__
29 #define __HC595_H__
30
31 #include "sim_irq.h"
32
33 /*
34  * this one is quite fun, it simulated a 74HC595 shift register
35  * driven by an SPI signal.
36  * For the interest of the simulation, they can be chained, but 
37  * for practicality sake the shift register is kept 32 bits
38  * wide so it acts as 4 of them "daisy chained" already. 
39  */
40 enum {
41         IRQ_HC595_SPI_BYTE_IN = 0,      // if hooked to a byte based SPI IRQ
42         IRQ_HC595_SPI_BYTE_OUT,         // to chain them !!
43         IRQ_HC595_IN_LATCH,
44         IRQ_HC595_IN_RESET,
45         IRQ_HC595_OUT,                          // when latched, output on this IRQ
46         IRQ_HC595_COUNT
47 };
48
49 typedef struct hc595_t {
50         avr_irq_t *     irq;            // irq list
51         uint32_t        latch;          // value "on the pins"
52         uint32_t        value;          // value shifted in
53 } hc595_t;
54
55 void
56 hc595_init(
57                 struct avr_t * avr,
58                 hc595_t *p);
59
60 #endif