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