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