mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:f782d9c66c49 1 /* mbed Microcontroller Library
dkato 0:f782d9c66c49 2 * Copyright (c) 2006-2013 ARM Limited
dkato 0:f782d9c66c49 3 *
dkato 0:f782d9c66c49 4 * Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:f782d9c66c49 5 * you may not use this file except in compliance with the License.
dkato 0:f782d9c66c49 6 * You may obtain a copy of the License at
dkato 0:f782d9c66c49 7 *
dkato 0:f782d9c66c49 8 * http://www.apache.org/licenses/LICENSE-2.0
dkato 0:f782d9c66c49 9 *
dkato 0:f782d9c66c49 10 * Unless required by applicable law or agreed to in writing, software
dkato 0:f782d9c66c49 11 * distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:f782d9c66c49 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:f782d9c66c49 13 * See the License for the specific language governing permissions and
dkato 0:f782d9c66c49 14 * limitations under the License.
dkato 0:f782d9c66c49 15 */
dkato 0:f782d9c66c49 16 #include "drivers/SPISlave.h"
dkato 0:f782d9c66c49 17
dkato 0:f782d9c66c49 18 #if DEVICE_SPISLAVE
dkato 0:f782d9c66c49 19
dkato 0:f782d9c66c49 20 namespace mbed {
dkato 0:f782d9c66c49 21
dkato 0:f782d9c66c49 22 SPISlave::SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
dkato 0:f782d9c66c49 23 _spi(),
dkato 0:f782d9c66c49 24 _bits(8),
dkato 0:f782d9c66c49 25 _mode(0),
dkato 0:f782d9c66c49 26 _hz(1000000)
dkato 0:f782d9c66c49 27 {
dkato 0:f782d9c66c49 28 spi_init(&_spi, mosi, miso, sclk, ssel);
dkato 0:f782d9c66c49 29 spi_format(&_spi, _bits, _mode, 1);
dkato 0:f782d9c66c49 30 spi_frequency(&_spi, _hz);
dkato 0:f782d9c66c49 31 }
dkato 0:f782d9c66c49 32
dkato 0:f782d9c66c49 33 void SPISlave::format(int bits, int mode) {
dkato 0:f782d9c66c49 34 _bits = bits;
dkato 0:f782d9c66c49 35 _mode = mode;
dkato 0:f782d9c66c49 36 spi_format(&_spi, _bits, _mode, 1);
dkato 0:f782d9c66c49 37 }
dkato 0:f782d9c66c49 38
dkato 0:f782d9c66c49 39 void SPISlave::frequency(int hz) {
dkato 0:f782d9c66c49 40 _hz = hz;
dkato 0:f782d9c66c49 41 spi_frequency(&_spi, _hz);
dkato 0:f782d9c66c49 42 }
dkato 0:f782d9c66c49 43
dkato 0:f782d9c66c49 44 int SPISlave::receive(void) {
dkato 0:f782d9c66c49 45 return(spi_slave_receive(&_spi));
dkato 0:f782d9c66c49 46 }
dkato 0:f782d9c66c49 47
dkato 0:f782d9c66c49 48 int SPISlave::read(void) {
dkato 0:f782d9c66c49 49 return(spi_slave_read(&_spi));
dkato 0:f782d9c66c49 50 }
dkato 0:f782d9c66c49 51
dkato 0:f782d9c66c49 52 void SPISlave::reply(int value) {
dkato 0:f782d9c66c49 53 spi_slave_write(&_spi, value);
dkato 0:f782d9c66c49 54 }
dkato 0:f782d9c66c49 55
dkato 0:f782d9c66c49 56 } // namespace mbed
dkato 0:f782d9c66c49 57
dkato 0:f782d9c66c49 58 #endif