fork from Sog

Dependencies:   NNN50_WIFI_API

Fork of mbed_SPIS_multiByte_example_SOG by Sog Yang

Committer:
sog_yang
Date:
Tue Jun 13 04:34:01 2017 +0000
Revision:
5:6a1155885fc9
Parent:
2:c520d7c7739d
Sog update version.

Who changed what in which revision?

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