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.
SPIDebug.cpp
00001 /////////////////////////////////////////////////////////////////////////////// 00002 // SPIDebug.h 00003 // 00004 // COPYRIGHT (c) 2012 by David Van Wagner 00005 // 00006 // dave@vanwagner.org 00007 // http://techwithdave.blogspot.com 00008 // 00009 // License: Creative Commons Attribution-ShareAlike 3.0 Unported License 00010 // http://creativecommons.org/licenses/by-sa/3.0/ 00011 /////////////////////////////////////////////////////////////////////////////// 00012 00013 #include "SPIDebug.h" 00014 00015 bool SPIDebug::debug = true; // default on 00016 00017 SPIDebug::SPIDebug(PinName mosi, PinName miso, PinName sclk, const char *name) 00018 { 00019 if (debug) 00020 printf("SPI(%08x, %08x, %08x, %s)\n", mosi, miso, sclk, name); 00021 spi = new SPI(mosi, miso, sclk, name); 00022 } 00023 00024 SPIDebug::~SPIDebug() 00025 { 00026 delete spi; 00027 } 00028 00029 void SPIDebug::format(int bits, int mode) 00030 { 00031 if (debug) 00032 printf("SPI.format(%d, %d)\n", bits, mode); 00033 spi->format(bits, mode); 00034 } 00035 00036 void SPIDebug::frequency(int hz) 00037 { 00038 if (debug) 00039 printf("SPI.frequency(%d)\n", hz); 00040 spi->frequency(hz); 00041 } 00042 00043 int SPIDebug::write(int value) 00044 { 00045 int result = spi->write(value); 00046 if (debug) 00047 printf(">%02x <%02x ", value, result); 00048 return result; 00049 } 00050 00051 CSDebug::CSDebug(PinName pin) 00052 { 00053 cs = new DigitalOut(pin); 00054 } 00055 00056 CSDebug::~CSDebug() 00057 { 00058 delete cs; 00059 } 00060 00061 void CSDebug::write(bool state) 00062 { 00063 cs->write(state); 00064 if (SPIDebug::debug) 00065 { 00066 if (state == false) 00067 printf("SPI CS\n"); 00068 else 00069 printf("\n"); 00070 } 00071 }
Generated on Sat Jul 16 2022 02:59:49 by
1.7.2