I2C hang recover function added
Dependencies: UniGraphic mbed vt100
In this version, check_i2c_pins function was added in edge_mgr.cpp.
プログラムの起動時、I2Cモジュールを初期化する前に、I2Cに使用するピンの電位を確認し
もし一方でも Low に張り付いていた場合、SCL を GPIO 出力に設定して
所定回数 (I2C_UNLOCK_TRIAL_CYCLE) 反転させることにより、疑似リセットクロックを生成します。
その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。
edge_sensor/edge_accel.h@2:de22987be9ba, 2018-06-18 (annotated)
- Committer:
- gaku_miyagawa
- Date:
- Mon Jun 18 02:55:38 2018 +0000
- Revision:
- 2:de22987be9ba
- Parent:
- 0:d895cd1cd897
SBU SPECIAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:d895cd1cd897 | 1 | #ifndef _EDGE_ACCEL_H_ |
Rhyme | 0:d895cd1cd897 | 2 | #define _EDGE_ACCEL_H_ |
Rhyme | 0:d895cd1cd897 | 3 | #include "mbed.h" |
Rhyme | 0:d895cd1cd897 | 4 | #include "edge_sensor.h" |
Rhyme | 0:d895cd1cd897 | 5 | #include "MMA8451Q.h" |
Rhyme | 0:d895cd1cd897 | 6 | |
Rhyme | 0:d895cd1cd897 | 7 | /** |
Rhyme | 0:d895cd1cd897 | 8 | * edge_accel edge_sensor which manage the accelerometer sensor (MMA8451Q) |
Rhyme | 0:d895cd1cd897 | 9 | * @note The behavior of this class is somewhat exceptional as an edge_sensor |
Rhyme | 0:d895cd1cd897 | 10 | * @note it samples and accumulates data which is the abs sum of current |
Rhyme | 0:d895cd1cd897 | 11 | * @note values and previous values every 0.1 sec |
Rhyme | 0:d895cd1cd897 | 12 | * @note and in each "interval" it delivers the averaged value |
Rhyme | 0:d895cd1cd897 | 13 | */ |
Rhyme | 0:d895cd1cd897 | 14 | |
Rhyme | 0:d895cd1cd897 | 15 | class edge_accel : public edge_sensor { |
Rhyme | 0:d895cd1cd897 | 16 | public: |
Rhyme | 0:d895cd1cd897 | 17 | /** |
Rhyme | 0:d895cd1cd897 | 18 | * constructor |
Rhyme | 0:d895cd1cd897 | 19 | * @param the MMA8451Q object |
Rhyme | 0:d895cd1cd897 | 20 | */ |
Rhyme | 0:d895cd1cd897 | 21 | edge_accel(MMA8451Q *accel) ; |
Rhyme | 0:d895cd1cd897 | 22 | |
Rhyme | 0:d895cd1cd897 | 23 | /** |
Rhyme | 0:d895cd1cd897 | 24 | * destructor |
Rhyme | 0:d895cd1cd897 | 25 | */ |
Rhyme | 0:d895cd1cd897 | 26 | ~edge_accel(void) ; |
Rhyme | 0:d895cd1cd897 | 27 | |
Rhyme | 0:d895cd1cd897 | 28 | /** |
Rhyme | 0:d895cd1cd897 | 29 | * clear and reset interval values |
Rhyme | 0:d895cd1cd897 | 30 | */ |
Rhyme | 0:d895cd1cd897 | 31 | virtual void reset(void) ; |
Rhyme | 0:d895cd1cd897 | 32 | // virtual void prepare(void) ; |
Rhyme | 0:d895cd1cd897 | 33 | |
Rhyme | 0:d895cd1cd897 | 34 | /** |
Rhyme | 0:d895cd1cd897 | 35 | * sample calculate the average value |
Rhyme | 0:d895cd1cd897 | 36 | * from _accumulation and _sample_count |
Rhyme | 0:d895cd1cd897 | 37 | * the average value is assigned to _value |
Rhyme | 0:d895cd1cd897 | 38 | * and currnt _sample_count is stored in _num_sampled |
Rhyme | 0:d895cd1cd897 | 39 | * then both _accumuation and _sample_count will be cleared |
Rhyme | 0:d895cd1cd897 | 40 | * @returns 0: success non-0: failure |
Rhyme | 0:d895cd1cd897 | 41 | */ |
Rhyme | 0:d895cd1cd897 | 42 | virtual int sample(void) ; |
Rhyme | 0:d895cd1cd897 | 43 | |
Rhyme | 0:d895cd1cd897 | 44 | /** |
Rhyme | 0:d895cd1cd897 | 45 | * deliver the value to the afero cloud |
Rhyme | 0:d895cd1cd897 | 46 | */ |
Rhyme | 0:d895cd1cd897 | 47 | virtual int deliver(void) ; |
Rhyme | 0:d895cd1cd897 | 48 | |
Rhyme | 0:d895cd1cd897 | 49 | /** |
Rhyme | 0:d895cd1cd897 | 50 | * show the data in the display (TFT) |
Rhyme | 0:d895cd1cd897 | 51 | */ |
Rhyme | 0:d895cd1cd897 | 52 | virtual void show(void) ; |
Rhyme | 0:d895cd1cd897 | 53 | |
Rhyme | 0:d895cd1cd897 | 54 | /** |
Rhyme | 0:d895cd1cd897 | 55 | * accum this is the real sampling |
Rhyme | 0:d895cd1cd897 | 56 | * and the differences of sampled values |
Rhyme | 0:d895cd1cd897 | 57 | * and previous values are calcurated and accumulated |
Rhyme | 0:d895cd1cd897 | 58 | * @returns 0: success non-0: failure |
Rhyme | 0:d895cd1cd897 | 59 | */ |
Rhyme | 0:d895cd1cd897 | 60 | int accum(void) ; |
Rhyme | 0:d895cd1cd897 | 61 | |
Rhyme | 0:d895cd1cd897 | 62 | /** |
Rhyme | 0:d895cd1cd897 | 63 | * Clear internal values |
Rhyme | 0:d895cd1cd897 | 64 | */ |
Rhyme | 0:d895cd1cd897 | 65 | void clear_value(void) ; |
Rhyme | 0:d895cd1cd897 | 66 | |
Rhyme | 0:d895cd1cd897 | 67 | private: |
Rhyme | 0:d895cd1cd897 | 68 | MMA8451Q *_accel ; |
Rhyme | 0:d895cd1cd897 | 69 | float _value ; |
Rhyme | 0:d895cd1cd897 | 70 | int32_t _num_sampled ; |
Rhyme | 0:d895cd1cd897 | 71 | int32_t _sample_count ; |
Rhyme | 0:d895cd1cd897 | 72 | int32_t _accumulation ; |
Rhyme | 0:d895cd1cd897 | 73 | int16_t _prev_x ; |
Rhyme | 0:d895cd1cd897 | 74 | int16_t _prev_y ; |
Rhyme | 0:d895cd1cd897 | 75 | int16_t _prev_z ; |
Rhyme | 0:d895cd1cd897 | 76 | } ; |
Rhyme | 0:d895cd1cd897 | 77 | |
Rhyme | 0:d895cd1cd897 | 78 | #endif /* _EDGE_ACCEL_H_ */ |