Dependents:   serial_connected_mcu_nucleo rotary_encoder_mbed serial_connected_mcu_nucleo omuni_speed_pid ... more

Fork of rotary_encoder by tarou yamada

このライブラリは以下のプログラムに基いています https://developer.mbed.org/users/gregeric/code/Nucleo_Hello_Encoder/

Files at this revision

API Documentation at this revision

Comitter:
inst
Date:
Sat May 21 02:50:07 2016 +0000
Parent:
4:d07f58c46a79
Child:
8:0a217d9f31c7
Commit message:
???????;

Changed in this revision

rotary_encoder.cpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder.hpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_a_phase.hpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_ab_phase.hpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_base/rotary_encoder_base.cpp Show annotated file Show diff for this revision Revisions of this file
rotary_encoder_base/rotary_encoder_base.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/rotary_encoder.cpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder.cpp	Sat May 21 02:50:07 2016 +0000
@@ -1,8 +1,6 @@
 #include "mbed.h"
 #include "rotary_encoder.hpp"
 
-namespace mbed_stl {
-
 const size_t rotary_encoder::max_counts_ = 0xFFFF;
 
 rotary_encoder::rotary_encoder(size_t resolution) :
@@ -12,5 +10,3 @@
 float rotary_encoder::get_revol_num() const {
     return static_cast<float>(get_counts()) / resolution_;
 }
-
-} /* namespace mbed_stl */
--- a/rotary_encoder.hpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder.hpp	Sat May 21 02:50:07 2016 +0000
@@ -1,11 +1,9 @@
-#ifndef INCLUDED_MBED_STL_ROTARY_ENCODER_H
-#define INCLUDED_MBED_STL_ROTARY_ENCODER_H
+#ifndef INCLUDED_ROTARY_ENCODER_H
+#define INCLUDED_ROTARY_ENCODER_H
 
 #include <stdint.h>
 #include <stddef.h>
 
-namespace mbed_stl {
-
 class rotary_encoder {
 public:
     rotary_encoder(size_t resolution);
@@ -23,6 +21,4 @@
     const size_t resolution_;
 };
 
-} /* namespace mbed_stl */
-
 #endif
--- a/rotary_encoder_a_phase.hpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_a_phase.hpp	Sat May 21 02:50:07 2016 +0000
@@ -1,36 +1,14 @@
-#ifndef INCLUDED_MBED_STL_ROTARY_ENCODER_A_PHASE_H
-#define INCLUDED_MBED_STL_ROTARY_ENCODER_A_PHASE_H
+#ifndef INCLUDED_ROTARY_ENCODER_A_PHASE_H
+#define INCLUDED_ROTARY_ENCODER_A_PHASE_H
 
 #include "rotary_encoder_base.hpp"
 #include "mbed.h"
 
-/*
- * TIM1_CH1: AF1 @ PA_8
- * TIM1_CH2: AF1 @ PA_9
- *
- * TIM2_CH1: AF1 @ PA_0
- * TIM2_CH2: AF1 @ PA_1
- *
- * TIM3_CH1: AF2 @ PB_4
- * TIM3_CH2: AF2 @ PB_5
- *
- * TIM4_CH1: AF2 @ PB_6, PD_12
- * TIM4_CH2: AF2 @ PB_7, PD_13
- *
- * TIM5_CH1: AF2 @ PA_0*    *TIM5 used by mbed system ticker so unavailable
- * TIM5_CH2: AF2 @ PA_1*
- *
- */
- 
-namespace mbed_stl {
-
 class rotary_encoder_a_phase : public rotary_encoder_base {
 public:
-    rotary_encoder_a_phase(TIM_TypeDef* timer_type, size_t resolution) :
-        rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI1, resolution) {}
+    rotary_encoder_a_phase(TIM_TypeDef* timer_type, size_t pulse_per_revol) : // A相での分解能はパルス数の倍
+        rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI1, pulse_per_revol << 1) {}
     virtual ~rotary_encoder_a_phase() {}
 };
 
-} /* namespace mbed_stl */
-
 #endif
--- a/rotary_encoder_ab_phase.hpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_ab_phase.hpp	Sat May 21 02:50:07 2016 +0000
@@ -1,36 +1,14 @@
-#ifndef INCLUDED_MBED_STL_ROTARY_ENCODER_AB_PHASE_H
-#define INCLUDED_MBED_STL_ROTARY_ENCODER_AB_PHASE_H
+#ifndef INCLUDED_ROTARY_ENCODER_AB_PHASE_H
+#define INCLUDED_ROTARY_ENCODER_AB_PHASE_H
 
 #include "rotary_encoder_base.hpp"
 #include "mbed.h"
 
-/*
- * TIM1_CH1: AF1 @ PA_8
- * TIM1_CH2: AF1 @ PA_9
- *
- * TIM2_CH1: AF1 @ PA_0
- * TIM2_CH2: AF1 @ PA_1
- *
- * TIM3_CH1: AF2 @ PB_4
- * TIM3_CH2: AF2 @ PB_5
- *
- * TIM4_CH1: AF2 @ PB_6, PD_12
- * TIM4_CH2: AF2 @ PB_7, PD_13
- *
- * TIM5_CH1: AF2 @ PA_0*    *TIM5 used by mbed system ticker so unavailable
- * TIM5_CH2: AF2 @ PA_1*
- *
- */
- 
-namespace mbed_stl {
-
 class rotary_encoder_ab_phase : public rotary_encoder_base {
 public:
-    rotary_encoder_ab_phase(TIM_TypeDef* timer_type, size_t resolution) :
-        rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI12, resolution) {}
+    rotary_encoder_ab_phase(TIM_TypeDef* timer_type, size_t pulse_per_revol) : // AB相での分解能はパルス数の4倍
+        rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI12, pulse_per_revol << 2) {}
     virtual ~rotary_encoder_ab_phase() {}
 };
 
-} /* namespace mbed_stl */
-
 #endif
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_abz_phase/rotary_encoder_abz_phase.cpp	Sat May 21 02:50:07 2016 +0000
@@ -2,8 +2,6 @@
 #include "rotary_encoder_abz_phase.hpp"
 #include "rotary_encoder_base.hpp"
 
-namespace mbed_stl {
-
 rotary_encoder_abz_phase::rotary_encoder_abz_phase(TIM_TypeDef* timer_type, PinName z_pin, size_t resolution) :
         rotary_encoder_base(timer_type, TIM_ENCODERMODE_TI12, resolution),
         z_phase_intr_(z_pin),
@@ -38,5 +36,3 @@
     counts_in_prev_intr_ = 0;
     timer_handler_.Instance->CNT = 0;
 }
-
-} /* namespace mbed_stl */
--- a/rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_abz_phase/rotary_encoder_abz_phase.hpp	Sat May 21 02:50:07 2016 +0000
@@ -4,26 +4,6 @@
 #include "rotary_encoder_base.hpp"
 #include "mbed.h"
 
-/*
- * TIM1_CH1: AF1 @ PA_8
- * TIM1_CH2: AF1 @ PA_9
- *
- * TIM2_CH1: AF1 @ PA_0
- * TIM2_CH2: AF1 @ PA_1
- *
- * TIM3_CH1: AF2 @ PB_4
- * TIM3_CH2: AF2 @ PB_5
- *
- * TIM4_CH1: AF2 @ PB_6, PD_12
- * TIM4_CH2: AF2 @ PB_7, PD_13
- *
- * TIM5_CH1: AF2 @ PA_0*    *TIM5 used by mbed system ticker so unavailable
- * TIM5_CH2: AF2 @ PA_1*
- *
- */
- 
-namespace mbed_stl {
-
 class rotary_encoder_abz_phase : public rotary_encoder_base {
 public:
     rotary_encoder_abz_phase(TIM_TypeDef* timer_type, PinName z_pin, size_t resolution);
@@ -40,6 +20,4 @@
     uint32_t counts_in_prev_intr_;
 };
 
-} /* namespace mbed_stl */
-
 #endif
--- a/rotary_encoder_base/rotary_encoder_base.cpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_base/rotary_encoder_base.cpp	Sat May 21 02:50:07 2016 +0000
@@ -2,19 +2,9 @@
 #include "rotary_encoder.hpp"
 #include "mbed.h"
 
-namespace mbed_stl {
-
 rotary_encoder_base::rotary_encoder_base(TIM_TypeDef* timer_type,
                                         uint32_t encoder_mode,
                                         size_t resolution) : rotary_encoder(resolution) {
-                                            
-                                            
-    
-    // todo:delete debug
-    encoder_mode = TIM_ENCODERMODE_TI12;
-    resolution = 400;
-    
-    
     timer_handler_.Instance              = timer_type;
     timer_handler_.Init.Period           = max_counts_;
     timer_handler_.Init.CounterMode      = TIM_COUNTERMODE_UP;
@@ -34,13 +24,9 @@
     encoder.IC2Prescaler    = TIM_ICPSC_DIV4;
     encoder.IC2Selection    = TIM_ICSELECTION_DIRECTTI;
     
-    ////////////////////////////////////////
-    //printf("t:%d, e:%d", &timer_handler_, &encoder);
     if (HAL_TIM_Encoder_Init(&timer_handler_, &encoder) != HAL_OK) {
         error("couldn't init encoder\n");
     }
-    //printf("%d end\n", cnt++);
-    ///////////////////////////////////////////
 }
 
 rotary_encoder_base::~rotary_encoder_base() {}
@@ -69,5 +55,3 @@
         error("couldn't start encoder\r\n");
     }
 }
-
-} /* namespace mbed_stl */
--- a/rotary_encoder_base/rotary_encoder_base.hpp	Sun Apr 03 06:30:19 2016 +0000
+++ b/rotary_encoder_base/rotary_encoder_base.hpp	Sat May 21 02:50:07 2016 +0000
@@ -1,11 +1,9 @@
-#ifndef INCLUDED_MBED_STL_ROTARY_ENCODER_BASE_H
-#define INCLUDED_MBED_STL_ROTARY_ENCODER_BASE_H
+#ifndef INCLUDED_ROTARY_ENCODER_BASE_H
+#define INCLUDED_ROTARY_ENCODER_BASE_H
 
 #include "mbed.h"
 #include "rotary_encoder.hpp"
 
-namespace mbed_stl {
-
 class rotary_encoder_base : public rotary_encoder {
 public:
     rotary_encoder_base(TIM_TypeDef* timer_type,
@@ -23,7 +21,4 @@
     TIM_HandleTypeDef timer_handler_;
 };
 
-
-} /* namespace mbed_stl */
-
 #endif