Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
SPI.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #include "SPI.h" 00017 00018 #if DEVICE_SPI 00019 00020 namespace mbed { 00021 00022 SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused) : 00023 _spi(), 00024 _bits(8), 00025 _mode(0), 00026 _hz(1000000) { 00027 spi_init(&_spi, mosi, miso, sclk, NC); 00028 spi_format(&_spi, _bits, _mode, 0); 00029 spi_frequency(&_spi, _hz); 00030 } 00031 00032 void SPI::format(int bits, int mode) { 00033 _bits = bits; 00034 _mode = mode; 00035 SPI::_owner = NULL; // Not that elegant, but works. rmeyer 00036 aquire(); 00037 } 00038 00039 void SPI::frequency(int hz) { 00040 _hz = hz; 00041 SPI::_owner = NULL; // Not that elegant, but works. rmeyer 00042 aquire(); 00043 } 00044 00045 SPI* SPI::_owner = NULL; 00046 00047 // ignore the fact there are multiple physical spis, and always update if it wasnt us last 00048 void SPI::aquire() { 00049 if (_owner != this) { 00050 spi_format(&_spi, _bits, _mode, 0); 00051 spi_frequency(&_spi, _hz); 00052 _owner = this; 00053 } 00054 } 00055 00056 int SPI::write(int value) { 00057 aquire(); 00058 return spi_master_write(&_spi, value); 00059 } 00060 00061 } // namespace mbed 00062 00063 #endif
Generated on Thu Jul 14 2022 13:45:20 by
