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

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [fx2/] [ztex-temp1.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   ZTEX Firmware Kit for EZ-USB FX2 Microcontrollers
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This Source Code Form is subject to the terms of the Mozilla Public
7
   License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
   You can obtain one at http://mozilla.org/MPL/2.0/.
9
 
10
   Alternatively, the contents of this file may be used under the terms
11
   of the GNU General Public License Version 3, as described below:
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License version 3 as
15
   published by the Free Software Foundation.
16
 
17
   This program is distributed in the hope that it will be useful, but
18
   WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
   General Public License for more details.
21
 
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, see http://www.gnu.org/licenses/.
24
%*/
25
 
26
/*
27
    Temperature sensor support for USB-FPGA Modules 1.15y
28
*/
29
 
30
#ifndef[ZTEX_TEMP1_H]
31
#define[ZTEX_TEMP1_H]
32
 
33
#define[TEMP1_ENABLED][1]
34
 
35
#define[PCA9691_ADDR][0x90]
36
 
37
void temp1_init() {
38
    I2CS |= bmBIT7;             // start bit
39
    i2c_waitStart();
40
    I2DAT = PCA9691_ADDR;               // select device for writing
41
    if ( i2c_waitWrite() ) return;
42
    I2DAT = bmBIT2 | bmBIT6;    // control byte
43
    if ( i2c_waitWrite() ) return;
44
    I2DAT = 20;                 // DAC output
45
    I2CS |= bmBIT6;             // stop bit
46
    if ( i2c_waitStop() ) return;
47
    INTERFACE_CAPABILITIES[1] |= bmBIT0;
48
}
49
 
50
 
51
ADD_EP0_VENDOR_REQUEST((0x58,,
52
    I2CS |= bmBIT7;             // start bit
53
    i2c_waitStart();
54
    I2DAT = PCA9691_ADDR | 1;   // select device for reading
55
    i2c_waitWrite();
56
 
57
    EP0BUF[0] = 1;               // protocol #1
58
 
59
    EP0BUF[1] = I2DAT;          // dummy read
60
    i2c_waitRead();
61
    EP0BUF[1] = I2DAT;          // BYTE 0
62
    i2c_waitRead();
63
    EP0BUF[2] = I2DAT;          // BYTE 1
64
    i2c_waitRead();
65
    EP0BUF[3] = I2DAT;          // BYTE 2
66
    i2c_waitRead();
67
    EP0BUF[4] = I2DAT;          // BYTE 3
68
    i2c_waitRead();
69
    EP0BUF[1] = I2DAT;          // BYTE 4
70
    i2c_waitRead();
71
    EP0BUF[2] = I2DAT;          // BYTE 5
72
    i2c_waitRead();
73
    I2CS |= bmBIT5;             // no ACK
74
    EP0BUF[3] = I2DAT;          // BYTE 6
75
    i2c_waitRead();
76
    I2CS |= bmBIT6;             // stop bit
77
    EP0BUF[4] = I2DAT;          // BYTE 7
78
    i2c_waitStop();
79
 
80
    EP0BCH = 0;
81
    EP0BCL = 5;
82
,,
83
));;
84
 
85
 
86
#endif  /*ZTEX_TEMP1_H*/

powered by: WebSVN 2.1.0

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