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