Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
YGE25i.cpp@0:288363538e78, 2010-11-27 (annotated)
- Committer:
- VipaSpeed
- Date:
- Sat Nov 27 21:00:12 2010 +0000
- Revision:
- 0:288363538e78
- Child:
- 1:892cfa205088
V0.1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| VipaSpeed | 0:288363538e78 | 1 | /** |
| VipaSpeed | 0:288363538e78 | 2 | * @section LICENSE |
| VipaSpeed | 0:288363538e78 | 3 | * |
| VipaSpeed | 0:288363538e78 | 4 | * Copyright (c) 2010 Christian Zagel |
| VipaSpeed | 0:288363538e78 | 5 | * |
| VipaSpeed | 0:288363538e78 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| VipaSpeed | 0:288363538e78 | 7 | * of this software and associated documentation files (the "Software"), to deal |
| VipaSpeed | 0:288363538e78 | 8 | * in the Software without restriction, including without limitation the rights |
| VipaSpeed | 0:288363538e78 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| VipaSpeed | 0:288363538e78 | 10 | * copies of the Software, and to permit persons to whom the Software is |
| VipaSpeed | 0:288363538e78 | 11 | * furnished to do so, subject to the following conditions: |
| VipaSpeed | 0:288363538e78 | 12 | * |
| VipaSpeed | 0:288363538e78 | 13 | * The above copyright notice and this permission notice shall be included in |
| VipaSpeed | 0:288363538e78 | 14 | * all copies or substantial portions of the Software. |
| VipaSpeed | 0:288363538e78 | 15 | * |
| VipaSpeed | 0:288363538e78 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| VipaSpeed | 0:288363538e78 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| VipaSpeed | 0:288363538e78 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| VipaSpeed | 0:288363538e78 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| VipaSpeed | 0:288363538e78 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| VipaSpeed | 0:288363538e78 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| VipaSpeed | 0:288363538e78 | 22 | * THE SOFTWARE. |
| VipaSpeed | 0:288363538e78 | 23 | * |
| VipaSpeed | 0:288363538e78 | 24 | * @section DESCRIPTION |
| VipaSpeed | 0:288363538e78 | 25 | * |
| VipaSpeed | 0:288363538e78 | 26 | * YGE25i Regler |
| VipaSpeed | 0:288363538e78 | 27 | * |
| VipaSpeed | 0:288363538e78 | 28 | */ |
| VipaSpeed | 0:288363538e78 | 29 | |
| VipaSpeed | 0:288363538e78 | 30 | /** |
| VipaSpeed | 0:288363538e78 | 31 | * Includes |
| VipaSpeed | 0:288363538e78 | 32 | */ |
| VipaSpeed | 0:288363538e78 | 33 | #include "YGE25i.h" |
| VipaSpeed | 0:288363538e78 | 34 | |
| VipaSpeed | 0:288363538e78 | 35 | YGE25i::YGE25i(PinName sda, PinName scl,int adress_) : i2c_(sda, scl) |
| VipaSpeed | 0:288363538e78 | 36 | { |
| VipaSpeed | 0:288363538e78 | 37 | //200kHz, normal mode. |
| VipaSpeed | 0:288363538e78 | 38 | i2c_.frequency(200000); |
| VipaSpeed | 0:288363538e78 | 39 | adress=adress_; |
| VipaSpeed | 0:288363538e78 | 40 | save_.attach(this,&YGE25i::YGESetPWMSave,0.75); |
| VipaSpeed | 0:288363538e78 | 41 | int a=34; |
| VipaSpeed | 0:288363538e78 | 42 | while(a>0) |
| VipaSpeed | 0:288363538e78 | 43 | { |
| VipaSpeed | 0:288363538e78 | 44 | wait_ms(1); |
| VipaSpeed | 0:288363538e78 | 45 | YGESetPWM(0); |
| VipaSpeed | 0:288363538e78 | 46 | a--; |
| VipaSpeed | 0:288363538e78 | 47 | } |
| VipaSpeed | 0:288363538e78 | 48 | } |
| VipaSpeed | 0:288363538e78 | 49 | |
| VipaSpeed | 0:288363538e78 | 50 | char YGE25i::YGEReadReg(char reg) |
| VipaSpeed | 0:288363538e78 | 51 | { |
| VipaSpeed | 0:288363538e78 | 52 | char rx; |
| VipaSpeed | 0:288363538e78 | 53 | reg=reg|0x80; |
| VipaSpeed | 0:288363538e78 | 54 | int ack=1; |
| VipaSpeed | 0:288363538e78 | 55 | ack=i2c_.write(adress & 0xFE, ®, 1); |
| VipaSpeed | 0:288363538e78 | 56 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 57 | ack=i2c_.read(adress | 0x01, &rx, 1); |
| VipaSpeed | 0:288363538e78 | 58 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 59 | return rx; |
| VipaSpeed | 0:288363538e78 | 60 | |
| VipaSpeed | 0:288363538e78 | 61 | } |
| VipaSpeed | 0:288363538e78 | 62 | |
| VipaSpeed | 0:288363538e78 | 63 | int YGE25i::YGEWriteReg(char reg, char data) |
| VipaSpeed | 0:288363538e78 | 64 | { |
| VipaSpeed | 0:288363538e78 | 65 | char tx[2]; |
| VipaSpeed | 0:288363538e78 | 66 | int ack=1; |
| VipaSpeed | 0:288363538e78 | 67 | tx[0] = reg|0x80; |
| VipaSpeed | 0:288363538e78 | 68 | tx[1] = data; |
| VipaSpeed | 0:288363538e78 | 69 | |
| VipaSpeed | 0:288363538e78 | 70 | ack=i2c_.write(adress & 0xFE, tx, 2); |
| VipaSpeed | 0:288363538e78 | 71 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 72 | else |
| VipaSpeed | 0:288363538e78 | 73 | return 0; |
| VipaSpeed | 0:288363538e78 | 74 | |
| VipaSpeed | 0:288363538e78 | 75 | } |
| VipaSpeed | 0:288363538e78 | 76 | |
| VipaSpeed | 0:288363538e78 | 77 | |
| VipaSpeed | 0:288363538e78 | 78 | int YGE25i::YGESetPWM( char pwm_) |
| VipaSpeed | 0:288363538e78 | 79 | { |
| VipaSpeed | 0:288363538e78 | 80 | pwm=pwm_; |
| VipaSpeed | 0:288363538e78 | 81 | char tx; |
| VipaSpeed | 0:288363538e78 | 82 | tx=pwm_ & 0x7f; |
| VipaSpeed | 0:288363538e78 | 83 | int ack; |
| VipaSpeed | 0:288363538e78 | 84 | ack=i2c_.write(adress & 0xFE, &tx, 1); |
| VipaSpeed | 0:288363538e78 | 85 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 86 | else |
| VipaSpeed | 0:288363538e78 | 87 | return 0; |
| VipaSpeed | 0:288363538e78 | 88 | |
| VipaSpeed | 0:288363538e78 | 89 | } |
| VipaSpeed | 0:288363538e78 | 90 | |
| VipaSpeed | 0:288363538e78 | 91 | void YGE25i::setAdress(int adress_) |
| VipaSpeed | 0:288363538e78 | 92 | { |
| VipaSpeed | 0:288363538e78 | 93 | adress=adress_; |
| VipaSpeed | 0:288363538e78 | 94 | } |
| VipaSpeed | 0:288363538e78 | 95 | |
| VipaSpeed | 0:288363538e78 | 96 | void YGE25i::YGESetPWMSave(void) |
| VipaSpeed | 0:288363538e78 | 97 | { |
| VipaSpeed | 0:288363538e78 | 98 | char tx; |
| VipaSpeed | 0:288363538e78 | 99 | tx=pwm & 0x7f; |
| VipaSpeed | 0:288363538e78 | 100 | i2c_.write(adress & 0xFE, &tx, 1); |
| VipaSpeed | 0:288363538e78 | 101 | } |
| VipaSpeed | 0:288363538e78 | 102 | |
| VipaSpeed | 0:288363538e78 | 103 |