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