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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [cortexm/] [a2fxxx/] [a2f200_eval/] [current/] [src/] [platform_i2c.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      platform_i2c.c
4
//
5
//      Optional I2C support for Cortex-M3 Actel Smartfusion
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2011 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):    ccoutand
43
// Contributors:
44
// Date:         2011-04-08
45
// Purpose:
46
// Description:
47
//
48
//####DESCRIPTIONEND####
49
//
50
//==========================================================================
51
 
52
 
53
//=============================================================================
54
//                               INCLUDES
55
//=============================================================================
56
#include <pkgconf/system.h>
57
#include <cyg/infra/cyg_type.h>
58
#include <cyg/hal/hal_arch.h>
59
#include <cyg/hal/hal_io.h>
60
#include <cyg/infra/cyg_ass.h>
61
#include <cyg/hal/hal_endian.h>
62
#include <cyg/hal/hal_intr.h>
63
 
64
#ifdef CYGPKG_DEVS_I2C_CORTEXM_A2FXXX
65
 
66
#include <cyg/io/i2c.h>
67
#include <cyg/io/i2c_a2fxxx.h>
68
 
69
//=============================================================================
70
// Setup I2C bus 0
71
//
72
static void
73
a2fxxx_i2c0_init( struct cyg_i2c_bus *bus )
74
{
75
    cyg_uint32 scl_io = CYGHWR_HAL_A2FXXX_I2C0_SCL;
76
    cyg_uint32 sda_io = CYGHWR_HAL_A2FXXX_I2C0_SDA;
77
 
78
    //
79
    // We only need to setup the pins here and
80
    // leave the I2C driver to take care of the rest.
81
    //
82
    CYGHWR_HAL_A2FXXX_GPIO_SET( scl_io );
83
    CYGHWR_HAL_A2FXXX_GPIO_SET( sda_io );
84
 
85
    a2fxxx_i2c_init( bus );
86
}
87
 
88
 
89
//-----------------------------------------------------------------------------
90
// I2C bus 0
91
//
92
CYG_A2FXXX_I2C_BUS(hal_a2fxxx_i2c0_bus,
93
                 &a2fxxx_i2c0_init,
94
                 CYGHWR_HAL_A2FXXX_I2C0,       // Base address
95
                 CYGHWR_HAL_A2FXXX_I2C0_BB,    // Bit-band base address
96
                 CYGHWR_HAL_A2FXXX_SC_CLR_SOFTRST_CR_I2C0,
97
                 CYGNUM_HAL_INTERRUPT_I2C0_0,
98
                 CYGNUM_DEVS_I2C_CORTEXM_A2FXXX_I2C0_ISR_PRIORITY);
99
 
100
 
101
//-----------------------------------------------------------------------------
102
// OLED
103
//
104
CYG_I2C_DEVICE(i2c_a2fxxx_oled,
105
               &hal_a2fxxx_i2c0_bus,
106
               0x3c,
107
               0,
108
               CYG_I2C_DEFAULT_DELAY);
109
 
110
 
111
#define DELAY 1
112
 
113
// Wrapper to OLED driver
114
 
115
externC cyg_uint32
116
a2fxxx_oled_write_first( cyg_uint8 byte )
117
{
118
    cyg_uint32      result;
119
 
120
    cyg_i2c_transaction_begin( &i2c_a2fxxx_oled );
121
 
122
    result = cyg_i2c_transaction_tx( &i2c_a2fxxx_oled,
123
                                     true, ( cyg_uint8 * )&byte, 1, false );
124
 
125
#ifdef CYGPKG_KERNEL
126
    cyg_thread_delay( DELAY );
127
#endif
128
 
129
    return result;
130
}
131
 
132
externC cyg_uint32
133
a2fxxx_oled_write_byte( cyg_uint8 byte )
134
{
135
    cyg_uint32      result;
136
 
137
    result = cyg_i2c_transaction_tx( &i2c_a2fxxx_oled,
138
                                     false, ( cyg_uint8 * )&byte, 1, false );
139
 
140
#ifdef CYGPKG_KERNEL
141
    cyg_thread_delay( DELAY );
142
#endif
143
 
144
    return result;
145
}
146
 
147
 
148
externC cyg_uint32
149
a2fxxx_oled_write_array( const cyg_uint8 *array, cyg_uint32 count )
150
{
151
    cyg_uint32      result;
152
 
153
    result = cyg_i2c_transaction_tx( &i2c_a2fxxx_oled,
154
                                     false, array, count, false );
155
 
156
    return result;
157
}
158
 
159
 
160
externC cyg_uint32
161
a2fxxx_oled_write_final( cyg_uint8 byte )
162
{
163
    cyg_uint32      result;
164
 
165
    result = cyg_i2c_transaction_tx( &i2c_a2fxxx_oled,
166
                                     false, ( cyg_uint8 * )&byte, 1, true );
167
#ifdef CYGPKG_KERNEL
168
    cyg_thread_delay( DELAY );
169
#endif
170
 
171
    cyg_i2c_transaction_end( &i2c_a2fxxx_oled );
172
 
173
    return result;
174
}
175
 
176
#endif // #ifdef CYGPKG_DEVS_I2C_CORTEXM_A2FXXX
177
 
178
//-----------------------------------------------------------------------------
179
// EOF platform_i2c.c

powered by: WebSVN 2.1.0

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