From 3611e58044ef705003171e55b9fd5003662c1466 Mon Sep 17 00:00:00 2001 From: askn37 Date: Thu, 18 Jul 2019 17:00:20 +0900 Subject: [PATCH] 0.1.5 --- README.md | 76 +++++----------------------------------------- keywords.txt | 3 -- library.properties | 2 +- src/Futilities.h | 1 - src/pcintvect.cpp | 57 ---------------------------------- src/pcintvect.h | 32 ------------------- 6 files changed, 8 insertions(+), 163 deletions(-) delete mode 100644 src/pcintvect.cpp delete mode 100644 src/pcintvect.h diff --git a/README.md b/README.md index 76bfb77..6072b1d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ // まとめて全部 #include #include -/* 注意 SoftwareSerial.h とは共存できない */ // あるいは必要なヘッダファイルだけ #include // AD比較変換 @@ -31,7 +30,6 @@ #include // 16進変換 #include // インターバルイベントクラス #include // メモリ情報 -#include // ピン変化割込 /* 注意 SoftwareSerial.h とは共存できない */ ``` # リファレンス @@ -46,7 +44,7 @@ - [16進変換](#hexdigh) - [インターバルイベントクラス](#IntervalEventh) (C++) - [メモリ情報](#memstath) -- [ピン変化割込](#pcintvecth) +- ~~[ピン変化割込](#pcintvecth)~~ 0.1.5で[PCIntVect](https://github.com/askn37PCIntVect)ライブラリに機能分離 ---- @@ -688,80 +686,20 @@ size_t freeSize = memFreeSize(); ---- -## pcintvect.h - -ピン変化割込 - -依存性: - -注意: -SoftwareSerial とは併用できない。 - -### void attachPCInterrupt (uint8\_t interruptPin, void (*userFunc)(void) = NULL) - -指定のピンに対応する外部ピン変化割込を有効にし、 -指定のユーザー定義ルーチンを割込ベクタに割り付ける。 - -通常の attachInterrupt() と違って、第1引数にはピン番号を直接記述する。 -また割込種別は EDGE しかないため、第3引数はない。 -第2引数の割込ベクタは同一ポートグループに属する各最大8本のピンで共有され、 -個々のピンに個別に割り当てるものではないことに注意。 - -MCU休止状態の解除のように、割込発生の事実だけを利用して割込処理が不要であるなら、第2引数には NULLを指定する。 - -割込ベクタ(ポートグループ)は PCINT0からPCINT3の最大4つがあるが、 -MCUの品種によってピン割付定義が異なる。 -また Arduino の表向きのピン番号とも一致しない。 - -|MCU|PCINT0|PCINT1|PCINT2|PCINT3|品種| -|---|---|---|---|---|---| -|ATmega328P|8 9 10 11 12 13|A0 A1 A2 A3 A4 A5 (A6 A7)|0 1 2 3 4 5 6 7|---|UNO ProMini| -|ATmega32U4|8 9 10 11 (14 15 16 17)|---|---|---|Leonardo ProMicro| -|ATmega1284P|A0 A1 A2 A3 A4 A5 A6 A7|4 5 6 7 10 11 12 13|22 23 24 25 26 27 28 29|0 1 2 3 8 9 30 31|Boubino| - -いくつかのピンは、attachInterrupt() での割込指定と独立して共存する。 -あるいは HardwareSerial や SPI や I2C の割込とも独立して共存する。 -つまりそれらの専用機能割込とは全く別に、干渉せずに使用できる。 - -例えば HardwareSerial は MCUが休止中は割込を発生しないが、 -外部ピン変化割込は検出され、休止状態を解除させることができる。 -両方を併用することで MCUを適切な省電力状態に置くことができる。 -個々の割込でのピン状態(HIGH・LOW、あるいは立ち上がり・立ち下がり変化)はソフトウェアで判断しなければできないが、 -休止状態解除目的に限ればそういった処理は省略可能である。 - -ポートグループ内のどのピンが割込発生要因になったかを判断するのは難しい。 -だが異なるポートグループの単一のピンに限って使用するのであれば、 -そのピンのHIGH・LOW変化だけを調べれば良いので単純であるし、 -普通はそのようにして使うだろう。 -SoftwareSerial はまさにそのようにして外部ピン変化割込を利用している。 - -### void detachPCInterrupt (uint8\_t interruptPin) - -指定のピンに対応するPCINT割込を解除する。 -対応するポートグループの割込ベクタも解除される。 - -同一ポートグループに複数の attachPCInterrupt() 割り付けをしていた場合、 -重複管理は行っていないので、まだほかで使われているにもかかわらず、 -ポートグループベクタそのものが消されてしまう。 -つまり detachPCInterrupt() の多用を前提にするなら、重複管理を行うか、 -元からポートグループが共有されないように割込用の物理ピン配線を熟考すべきだろう。 -Arduino.h で外部ピン変化割込が標準実装されていないのは、この分かり難さによるだろう。 - ----- - ## 既知の不具合/制約/課題 - 主要な AVR 以外はテストされていない。 - 古い Arduino IDE には対応しない。1.8.5で動作確認。少なくとも C++11 は使えなければならない。 -- 文中で繰り返し断っているが、pcintvect.h は SoftwareSerial.h と共存できない。 -同様に PCInt Vecotr を排他的に使用するライブラリは使用できない。 - 英文マニュアルが未整備である。 ## 改版履歴 -- 0.1.4 - - pcintvect を SoftwareSerial が先にインクルードされている場合は、無効化するように修正。 - - pcintvect で PCINT4_vect も扱うように修正。 +- 0.1.5 + - pcintvect を別ライブラリに除外。 + +- ~~0.1.4~~ + - ~~pcintvect を SoftwareSerial が先にインクルードされている場合は、無効化するように修正。~~ + - ~~pcintvect で PCINT4_vect も扱うように修正。~~ - 0.1.3 - adcomp.h に getThermistor() を追加。 diff --git a/keywords.txt b/keywords.txt index 91edad4..ea4fa07 100644 --- a/keywords.txt +++ b/keywords.txt @@ -29,9 +29,6 @@ getThermistor KEYWORD2 acpSetup KEYWORD2 acpAttachInterrupt KEYWORD2 -attachPCInterrupt KEYWORD2 -detachPCInterrupt KEYWORD2 - digitalToggle KEYWORD2 dtoh KEYWORD2 diff --git a/library.properties b/library.properties index 4bfecbf..b151464 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Futilities -version=0.1.4 +version=0.1.5 author=askn maintainer=Kazuhiko Sato/askn sentence=A semi futility utilities library toolbox for Arduino diff --git a/src/Futilities.h b/src/Futilities.h index 9e32c3a..ce11a81 100644 --- a/src/Futilities.h +++ b/src/Futilities.h @@ -21,7 +21,6 @@ #include "hexdig.h" #include "IntervalEvent.h" #include "memstat.h" -#include "pcintvect.h" #endif diff --git a/src/pcintvect.cpp b/src/pcintvect.cpp deleted file mode 100644 index d4e6a71..0000000 --- a/src/pcintvect.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*************** - * - * pcintvect - PCINTn_vect helper utilities - * - * target architectures: Atmel AVR (ATmega 328P, 1284P and other) - * - * release site: https://github.com/askn37/Futilities - * maintainer: askn https://twitter.com/askn37 - * - */ - -#ifndef SoftwareSerial_h -#include -#include "pcintvect.h" - -volatile void __empty (void) {} -volatile void (*__pcint_vect[5])(void) = {__empty, __empty, __empty, __empty}; - -#if defined(PCINT0_vect) -ISR(PCINT0_vect, __attribute__ ((weak))) { __pcint_vect[0](); } -// ISR(PCINT0_vect) { __pcint_vect[0](); } -#endif -#if defined(PCINT1_vect) -ISR(PCINT1_vect, __attribute__ ((weak))) { __pcint_vect[1](); } -// ISR(PCINT1_vect) { __pcint_vect[1](); } -#endif -#if defined(PCINT2_vect) -ISR(PCINT2_vect, __attribute__ ((weak))) { __pcint_vect[2](); } -// ISR(PCINT2_vect) { __pcint_vect[2](); } -#endif -#if defined(PCINT3_vect) -ISR(PCINT3_vect, __attribute__ ((weak))) { __pcint_vect[3](); } -// ISR(PCINT3_vect) { __pcint_vect[3](); } -#endif -#if defined(PCINT4_vect) -ISR(PCINT4_vect, __attribute__ ((weak))) { __pcint_vect[4](); } -// ISR(PCINT4_vect) { __pcint_vect[3](); } -#endif - -void attachPCInterrupt (uint8_t interruptPin, void (*userFunc)(void)) { - int _pcint = digitalPinToPCICRbit(interruptPin); - __pcint_vect[_pcint & 3] = userFunc != NULL ? (volatile void (*)(void)) userFunc : (volatile void (*)(void)) __empty; - *digitalPinToPCMSK(interruptPin) |= _BV(digitalPinToPCMSKbit(interruptPin)); - PCIFR |= _BV(digitalPinToPCICRbit(interruptPin)); - PCICR |= _BV(digitalPinToPCICRbit(interruptPin)); -} - -void detachPCInterrupt (uint8_t interruptPin) { - int _pcint = digitalPinToPCICRbit(interruptPin); - __pcint_vect[_pcint & 3] = (volatile void (*)(void)) __empty; - *digitalPinToPCMSK(interruptPin) &= ~_BV(digitalPinToPCMSKbit(interruptPin)); - PCIFR &= ~_BV(digitalPinToPCICRbit(interruptPin)); - PCICR &= ~_BV(digitalPinToPCICRbit(interruptPin)); -} -#endif - -// end of code diff --git a/src/pcintvect.h b/src/pcintvect.h deleted file mode 100644 index 6c811e4..0000000 --- a/src/pcintvect.h +++ /dev/null @@ -1,32 +0,0 @@ -/*************** - * - * pcintvect - PCINTn_vect helper utilities - * - * target architectures: Atmel AVR (ATmega 328P, 1284P and other) - * - * release site: https://github.com/askn37/Futilities - * maintainer: askn https://twitter.com/askn37 - * - */ - -#ifndef SoftwareSerial_h -#ifndef __PCINTVECT_H -#define __PCINTVECT_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern void attachPCInterrupt (uint8_t, void (*)(void) = NULL); -extern void detachPCInterrupt (uint8_t); - -#ifdef __cplusplus -} -#endif - -#endif -#endif - -// end of header \ No newline at end of file