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