游戏王对战板,目前code还是空的

Committer:
WFKnight
Date:
Thu Jun 21 13:51:43 2018 +0000
Revision:
0:9b3d4731edbb
UART, RTOS, LED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WFKnight 0:9b3d4731edbb 1 /* mbed Microcontroller Library
WFKnight 0:9b3d4731edbb 2 * Copyright (c) 2006-2013 ARM Limited
WFKnight 0:9b3d4731edbb 3 *
WFKnight 0:9b3d4731edbb 4 * Licensed under the Apache License, Version 2.0 (the "License");
WFKnight 0:9b3d4731edbb 5 * you may not use this file except in compliance with the License.
WFKnight 0:9b3d4731edbb 6 * You may obtain a copy of the License at
WFKnight 0:9b3d4731edbb 7 *
WFKnight 0:9b3d4731edbb 8 * http://www.apache.org/licenses/LICENSE-2.0
WFKnight 0:9b3d4731edbb 9 *
WFKnight 0:9b3d4731edbb 10 * Unless required by applicable law or agreed to in writing, software
WFKnight 0:9b3d4731edbb 11 * distributed under the License is distributed on an "AS IS" BASIS,
WFKnight 0:9b3d4731edbb 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
WFKnight 0:9b3d4731edbb 13 * See the License for the specific language governing permissions and
WFKnight 0:9b3d4731edbb 14 * limitations under the License.
WFKnight 0:9b3d4731edbb 15 */
WFKnight 0:9b3d4731edbb 16 #include "drivers/I2CSlave.h"
WFKnight 0:9b3d4731edbb 17
WFKnight 0:9b3d4731edbb 18 #if DEVICE_I2CSLAVE
WFKnight 0:9b3d4731edbb 19
WFKnight 0:9b3d4731edbb 20 namespace mbed {
WFKnight 0:9b3d4731edbb 21
WFKnight 0:9b3d4731edbb 22 I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() {
WFKnight 0:9b3d4731edbb 23 i2c_init(&_i2c, sda, scl);
WFKnight 0:9b3d4731edbb 24 i2c_frequency(&_i2c, 100000);
WFKnight 0:9b3d4731edbb 25 i2c_slave_mode(&_i2c, 1);
WFKnight 0:9b3d4731edbb 26 }
WFKnight 0:9b3d4731edbb 27
WFKnight 0:9b3d4731edbb 28 void I2CSlave::frequency(int hz) {
WFKnight 0:9b3d4731edbb 29 i2c_frequency(&_i2c, hz);
WFKnight 0:9b3d4731edbb 30 }
WFKnight 0:9b3d4731edbb 31
WFKnight 0:9b3d4731edbb 32 void I2CSlave::address(int address) {
WFKnight 0:9b3d4731edbb 33 int addr = (address & 0xFF) | 1;
WFKnight 0:9b3d4731edbb 34 i2c_slave_address(&_i2c, 0, addr, 0);
WFKnight 0:9b3d4731edbb 35 }
WFKnight 0:9b3d4731edbb 36
WFKnight 0:9b3d4731edbb 37 int I2CSlave::receive(void) {
WFKnight 0:9b3d4731edbb 38 return i2c_slave_receive(&_i2c);
WFKnight 0:9b3d4731edbb 39 }
WFKnight 0:9b3d4731edbb 40
WFKnight 0:9b3d4731edbb 41 int I2CSlave::read(char *data, int length) {
WFKnight 0:9b3d4731edbb 42 return i2c_slave_read(&_i2c, data, length) != length;
WFKnight 0:9b3d4731edbb 43 }
WFKnight 0:9b3d4731edbb 44
WFKnight 0:9b3d4731edbb 45 int I2CSlave::read(void) {
WFKnight 0:9b3d4731edbb 46 return i2c_byte_read(&_i2c, 0);
WFKnight 0:9b3d4731edbb 47 }
WFKnight 0:9b3d4731edbb 48
WFKnight 0:9b3d4731edbb 49 int I2CSlave::write(const char *data, int length) {
WFKnight 0:9b3d4731edbb 50 return i2c_slave_write(&_i2c, data, length) != length;
WFKnight 0:9b3d4731edbb 51 }
WFKnight 0:9b3d4731edbb 52
WFKnight 0:9b3d4731edbb 53 int I2CSlave::write(int data) {
WFKnight 0:9b3d4731edbb 54 return i2c_byte_write(&_i2c, data);
WFKnight 0:9b3d4731edbb 55 }
WFKnight 0:9b3d4731edbb 56
WFKnight 0:9b3d4731edbb 57 void I2CSlave::stop(void) {
WFKnight 0:9b3d4731edbb 58 i2c_stop(&_i2c);
WFKnight 0:9b3d4731edbb 59 }
WFKnight 0:9b3d4731edbb 60
WFKnight 0:9b3d4731edbb 61 }
WFKnight 0:9b3d4731edbb 62
WFKnight 0:9b3d4731edbb 63 #endif