00001
00002
00003
00004 #ifndef NMC_PIC_IO_MSG_BUILDER_H
00005 #define NMC_PIC_IO_MSG_BUILDER_H
00006
00007
00008 #include "nmc_msg_builder.H"
00009
00010
00011 namespace nmc
00012 {
00013 namespace pic_io
00014 {
00015 static unsigned const NUM_LINES = 12;
00016
00017 enum status_report_t
00018 {
00019 STATUS_REPORT_INPUT_BITS = 0x01,
00020 STATUS_REPORT_AD1_VALUE = 0x02,
00021 STATUS_REPORT_AD2_VALUE = 0x04,
00022 STATUS_REPORT_AD3_VALUE = 0x08,
00023 STATUS_REPORT_COUNTER_TIMER = 0x10,
00024 STATUS_REPORT_DEVICE_TYPE = 0x20,
00025 STATUS_REPORT_SYNCH_INPUT_BITS = 0x40,
00026 STATUS_REPORT_SYNCH_COUNTER_TIMER = 0x80,
00027 };
00028
00029 class set_direction_builder_t : public msg_builder_t
00030 {
00031 public:
00032 set_direction_builder_t () : m_direction (0x0FFF) {}
00033
00034 void direction (unsigned line, bool is_input)
00035 {
00036 assert (line < NUM_LINES);
00037 m_direction &= ~(1 << line);
00038 m_direction |= (is_input << line);
00039 }
00040
00041 protected:
00042 u8_t _build (void);
00043
00044 u16_t m_direction;
00045 };
00046
00047 class define_status_builder_t : public msg_builder_t
00048 {
00049 public:
00050 define_status_builder_t () : m_report (0) {}
00051
00052 void report (status_report_t status)
00053 {
00054 m_report &= ~((u8_t) status);
00055 m_report |= (u8_t) status;
00056 }
00057
00058 protected:
00059 u8_t _build (void);
00060
00061 u8_t m_report;
00062 };
00063
00064 class read_status_builder_t : public msg_builder_t
00065 {
00066 public:
00067 read_status_builder_t () : m_report (0) {}
00068
00069 void report (status_report_t status)
00070 {
00071 m_report &= ~((u8_t) status);
00072 m_report |= (u8_t) status;
00073 }
00074
00075 protected:
00076 u8_t _build (void);
00077
00078 u8_t m_report;
00079 };
00080
00081 class set_pwm_builder_t : public msg_builder_t
00082 {
00083 public:
00084 set_pwm_builder_t () : m_pwm_1 (0), m_pwm_2 (0) {}
00085
00086 void pwm_1 (u8_t pwm) { m_pwm_1 = pwm; }
00087 void pwm_2 (u8_t pwm) { m_pwm_2 = pwm; }
00088
00089 protected:
00090 u8_t _build (void);
00091
00092 u8_t m_pwm_1;
00093 u8_t m_pwm_2;
00094 };
00095
00096 class synch_output_builder_t : public msg_builder_t
00097 {
00098 protected:
00099 u8_t _build (void);
00100 };
00101
00102 class set_output_builder_t : public msg_builder_t
00103 {
00104 public:
00105 set_output_builder_t () : m_outputs (0x0000) {}
00106
00107 void output (unsigned line, bool enable)
00108 {
00109 assert (line < 12);
00110 m_outputs &= ~(1 << line);
00111 m_outputs |= (((u16_t) enable) << line);
00112 }
00113
00114 protected:
00115 u8_t _build (void);
00116
00117 u16_t m_outputs;
00118 };
00119
00120 class set_synch_output_builder_t : public msg_builder_t
00121 {
00122 public:
00123 set_synch_output_builder_t () :
00124 m_outputs (0x0000), m_pwm_1 (0), m_pwm_2 (0) {}
00125
00126 void output (unsigned line, bool enable)
00127 {
00128 assert (line < 12);
00129 m_outputs &= ~(1 << line);
00130 m_outputs |= (((u16_t) enable) << line);
00131 }
00132 void pwm_1 (u8_t pwm) { m_pwm_1 = pwm; }
00133 void pwm_2 (u8_t pwm) { m_pwm_2 = pwm; }
00134
00135 protected:
00136 u8_t _build (void);
00137
00138 u16_t m_outputs;
00139 u8_t m_pwm_1;
00140 u8_t m_pwm_2;
00141 };
00142
00143 class set_timer_mode_builer_t : public msg_builder_t
00144 {
00145 public:
00146 enum ct_mode_t
00147 {
00148 MODE_TIMER = 0x00,
00149 MODE_COUNTER = 0x02,
00150 };
00151 enum ct_prescalar_t
00152 {
00153 PRESCALAR_1_1 = 0x00,
00154 PRESCALAR_2_1 = 0x10,
00155 PRESCALAR_4_1 = 0x20,
00156 PRESCALAR_8_1 = 0x30,
00157 };
00158
00159 set_timer_mode_builer_t () :
00160 m_enabled (false),
00161 m_ct_mode (MODE_TIMER)
00162 {}
00163
00164 void enable (bool is_enabled)
00165 { m_enabled = is_enabled; }
00166 void ct_mode (ct_mode_t mode) { m_ct_mode = mode; }
00167 void ct_prescalar (ct_prescalar_t prescalar)
00168 { m_ct_prescalar = prescalar; }
00169
00170 protected:
00171 u8_t _build (void);
00172
00173 bool m_enabled;
00174 ct_mode_t m_ct_mode;
00175 ct_prescalar_t m_ct_prescalar;
00176 };
00177
00178 class synch_input_builder_t : public msg_builder_t
00179 {
00180 protected:
00181 u8_t _build (void);
00182 };
00183 };
00184 };
00185
00186
00187 #endif