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

Subversion Repositories usb_fpga_2_04

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

powered by: WebSVN 2.1.0

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