出力ポートを,オープンドレインまたはプッシュプルに設定するグローバル関数の使用例. Example of global functions for setting the output port bits as open-drain or push-pull.
Dependencies: mbed UIT_SetOutputPortType
Diff: main.cpp
- Revision:
- 3:f9dc19059c3b
- Parent:
- 2:966a8ad956d3
- Child:
- 4:b8b4d42fa9fd
--- a/main.cpp Fri Sep 04 12:02:07 2015 +0000 +++ b/main.cpp Fri Oct 21 07:55:02 2016 +0000 @@ -3,33 +3,37 @@ // (Example of global functions for setting the output port bit // as open-drain or push-pull) // -// 2015/09/04, Copyright (c) 2015 MIKAMI, Naoki +// 2016/10/21, Copyright (c) 2016 MIKAMI, Naoki //--------------------------------------------------------------------------------- #include "SetOutputPortType.hpp" using namespace Mikami; -BusOut bus_(D2, D3, D4, D5, D6, D7, D8); -DigitalIn uButton_(USER_BUTTON); - // ユーザ・ボタン(青のボタン)を押すまで待つ関数 void WaitButton(char str[]) { + DigitalIn uButton(USER_BUTTON); printf(str); printf("\r\nPush blue button"); - while (uButton_ == 1) {} +#ifdef STM32F7 + while (uButton != 1) {} +#else + while (uButton == 1) {} +#endif wait(0.5); } int main() { + BusOut bus(D2, D3, D4, D5, D6, D7, D8); + // MODER I/O ポートを,入力/汎用出力/代替え機能/アナログに設定するレジスタ // PUPDR I/O ポートを,プルアップ,プルダウン,プルアップ・プルダウンなしに設定するレジスタ // OTYPER 出力のタイプをプッシュプル/オープンドレインに設定するレジスタ printf("\r\n\nGPIOB mode Reg.: 0x%08x", GPIOB->MODER); printf("\r\nGPIOB pull-up/pull-down Reg.: 0x%08x", GPIOB->PUPDR); - bus_ = 0x7F; + bus = 0x7F; SetOpenDrain(D2, D3, D4, D5, D6, D7, D8); printf("\r\n\nGPIOB output type Reg.: 0x%04x", GPIOB->OTYPER); printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); @@ -50,5 +54,20 @@ printf("\r\nGPIOA output type Reg.: 0x%04x", GPIOA->OTYPER); printf("\r\nD2 - D4: open drain\r\n"); +#ifdef STM32F7 + DigitalOut pg(PG_0, 0); + WaitButton("\r\nPG_0: push-pull, Output: 0\r\n"); + + pg = 1; + WaitButton("\r\nPG_0: push-pull, Output: 1\r\n"); + SetOpenDrain(PG_0); + + WaitButton("\r\nPG_0: Open RDain\r\n"); + SetPushPull(PG_0); + WaitButton("\r\nPG_0: push-pull\r\n"); +#endif + + printf("\r\nEnd of Test\r\n"); + while (true); }