Yihui Xiong / Mbed 2 deprecated Seeed_nRF51822_Motion

Dependencies:   mbed

Committer:
yihui
Date:
Mon Jan 11 02:32:24 2016 +0000
Revision:
0:638edba3adf6
initial

Who changed what in which revision?

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