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@3:01ad25aaff55, 2011-02-04 (annotated)
- Committer:
- VipaSpeed
- Date:
- Fri Feb 04 18:55:44 2011 +0000
- Revision:
- 3:01ad25aaff55
- Parent:
- 2:3b81b375ced3
- Child:
- 4:b6183c27ddfe
V1.2
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 | 1:892cfa205088 | 35 | YGE25i::YGE25i(PinName sda, PinName scl,int adress_) : i2c_(sda, scl){ |
| VipaSpeed | 1:892cfa205088 | 36 | |
| VipaSpeed | 0:288363538e78 | 37 | //200kHz, normal mode. |
| VipaSpeed | 0:288363538e78 | 38 | i2c_.frequency(200000); |
| VipaSpeed | 0:288363538e78 | 39 | adress=adress_; |
| VipaSpeed | 1:892cfa205088 | 40 | //save_.attach_us(this,&YGE25i::YGESetPWMSave,1000); |
| VipaSpeed | 1:892cfa205088 | 41 | |
| VipaSpeed | 0:288363538e78 | 42 | } |
| VipaSpeed | 0:288363538e78 | 43 | |
| VipaSpeed | 1:892cfa205088 | 44 | char YGE25i::YGEReadReg(char reg){ |
| VipaSpeed | 1:892cfa205088 | 45 | |
| VipaSpeed | 0:288363538e78 | 46 | char rx; |
| VipaSpeed | 0:288363538e78 | 47 | reg=reg|0x80; |
| VipaSpeed | 0:288363538e78 | 48 | int ack=1; |
| VipaSpeed | 0:288363538e78 | 49 | ack=i2c_.write(adress & 0xFE, ®, 1); |
| VipaSpeed | 0:288363538e78 | 50 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 51 | ack=i2c_.read(adress | 0x01, &rx, 1); |
| VipaSpeed | 0:288363538e78 | 52 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 53 | return rx; |
| VipaSpeed | 0:288363538e78 | 54 | |
| VipaSpeed | 0:288363538e78 | 55 | } |
| VipaSpeed | 0:288363538e78 | 56 | |
| VipaSpeed | 1:892cfa205088 | 57 | int YGE25i::YGEWriteReg(char reg, char data){ |
| VipaSpeed | 1:892cfa205088 | 58 | |
| VipaSpeed | 0:288363538e78 | 59 | char tx[2]; |
| VipaSpeed | 0:288363538e78 | 60 | int ack=1; |
| VipaSpeed | 0:288363538e78 | 61 | tx[0] = reg|0x80; |
| VipaSpeed | 0:288363538e78 | 62 | tx[1] = data; |
| VipaSpeed | 0:288363538e78 | 63 | |
| VipaSpeed | 0:288363538e78 | 64 | ack=i2c_.write(adress & 0xFE, tx, 2); |
| VipaSpeed | 0:288363538e78 | 65 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 66 | else |
| VipaSpeed | 0:288363538e78 | 67 | return 0; |
| VipaSpeed | 0:288363538e78 | 68 | |
| VipaSpeed | 0:288363538e78 | 69 | } |
| VipaSpeed | 0:288363538e78 | 70 | |
| VipaSpeed | 0:288363538e78 | 71 | |
| VipaSpeed | 1:892cfa205088 | 72 | int YGE25i::YGESetPWM( char pwm_){ |
| VipaSpeed | 1:892cfa205088 | 73 | |
| VipaSpeed | 0:288363538e78 | 74 | pwm=pwm_; |
| VipaSpeed | 0:288363538e78 | 75 | char tx; |
| VipaSpeed | 0:288363538e78 | 76 | tx=pwm_ & 0x7f; |
| VipaSpeed | 0:288363538e78 | 77 | int ack; |
| VipaSpeed | 0:288363538e78 | 78 | ack=i2c_.write(adress & 0xFE, &tx, 1); |
| VipaSpeed | 0:288363538e78 | 79 | if(ack!=0){return 255;} |
| VipaSpeed | 0:288363538e78 | 80 | else |
| VipaSpeed | 0:288363538e78 | 81 | return 0; |
| VipaSpeed | 0:288363538e78 | 82 | |
| VipaSpeed | 0:288363538e78 | 83 | } |
| VipaSpeed | 0:288363538e78 | 84 | |
| VipaSpeed | 1:892cfa205088 | 85 | void YGE25i::setAdress(int adress_){ |
| VipaSpeed | 1:892cfa205088 | 86 | |
| VipaSpeed | 0:288363538e78 | 87 | adress=adress_; |
| VipaSpeed | 1:892cfa205088 | 88 | } |
| VipaSpeed | 1:892cfa205088 | 89 | |
| VipaSpeed | 2:3b81b375ced3 | 90 | |
| VipaSpeed | 1:892cfa205088 | 91 | void YGE25i::YGESetPWMSave(void){ |
| VipaSpeed | 0:288363538e78 | 92 | char tx; |
| VipaSpeed | 0:288363538e78 | 93 | tx=pwm & 0x7f; |
| VipaSpeed | 0:288363538e78 | 94 | i2c_.write(adress & 0xFE, &tx, 1); |
| VipaSpeed | 0:288363538e78 | 95 | } |
| VipaSpeed | 2:3b81b375ced3 | 96 | |
| VipaSpeed | 2:3b81b375ced3 | 97 | void YGE25i::setPWM(int pwm_){ |
| VipaSpeed | 2:3b81b375ced3 | 98 | |
| VipaSpeed | 2:3b81b375ced3 | 99 | pwm=pwm_; |
| VipaSpeed | 3:01ad25aaff55 | 100 | } |
| VipaSpeed | 3:01ad25aaff55 | 101 | |
| VipaSpeed | 3:01ad25aaff55 | 102 | void YGE25i::initYGE(void){ |
| VipaSpeed | 3:01ad25aaff55 | 103 | |
| VipaSpeed | 3:01ad25aaff55 | 104 | for(int a=0;a<=40;a++){ |
| VipaSpeed | 3:01ad25aaff55 | 105 | |
| VipaSpeed | 3:01ad25aaff55 | 106 | wait_ms(10); |
| VipaSpeed | 3:01ad25aaff55 | 107 | YGESetPWM(0); |
| VipaSpeed | 3:01ad25aaff55 | 108 | |
| VipaSpeed | 3:01ad25aaff55 | 109 | } |
| VipaSpeed | 3:01ad25aaff55 | 110 | wait_ms(20); |
| VipaSpeed | 3:01ad25aaff55 | 111 | } |