1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-26 13:25:54 +00:00

Merge pull request #10919 from thinkyhead/bf1_misc_cleanups_jun2

[1.1.x] Clean up ST7565, dual endstops homing
This commit is contained in:
Scott Lahteine 2018-06-03 03:35:55 -05:00 committed by GitHub
commit 3be22fc1fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 147 additions and 146 deletions

View File

@ -1372,7 +1372,7 @@ bool get_target_extruder_from_command(const uint16_t code) {
#endif
#if ENABLED(DELTA)
switch(axis) {
switch (axis) {
#if HAS_SOFTWARE_ENDSTOPS
case X_AXIS:
case Y_AXIS:
@ -2937,9 +2937,14 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
SERIAL_ECHOPAIR(", ", distance);
SERIAL_ECHOPAIR(", ", fr_mm_s);
SERIAL_ECHOPAIR(" [", fr_mm_s ? fr_mm_s : homing_feedrate(axis));
SERIAL_ECHOLNPGM("])");
SERIAL_ECHOPGM(", ");
if (fr_mm_s)
SERIAL_ECHO(fr_mm_s);
else {
SERIAL_ECHOPAIR("[", homing_feedrate(axis));
SERIAL_CHAR(']');
}
SERIAL_ECHOLNPGM(")");
}
#endif
@ -3058,11 +3063,12 @@ static void homeaxis(const AxisEnum axis) {
}
#endif
const int axis_home_dir =
const int axis_home_dir = (
#if ENABLED(DUAL_X_CARRIAGE)
(axis == X_AXIS) ? x_home_dir(active_extruder) :
axis == X_AXIS ? x_home_dir(active_extruder) :
#endif
home_dir(axis);
home_dir(axis)
);
// Homing Z towards the bed? Deploy the Z probe or endstop.
#if HOMING_Z_WITH_PROBE
@ -3070,14 +3076,20 @@ static void homeaxis(const AxisEnum axis) {
#endif
// Set flags for X, Y, Z motor locking
#if ENABLED(X_DUAL_ENDSTOPS)
if (axis == X_AXIS) stepper.set_homing_flag_x(true);
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
if (axis == Y_AXIS) stepper.set_homing_flag_y(true);
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) stepper.set_homing_flag_z(true);
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
switch (axis) {
#if ENABLED(X_DUAL_ENDSTOPS)
case X_AXIS:
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
case Y_AXIS:
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
case Z_AXIS:
#endif
stepper.set_homing_dual_axis(true);
default: break;
}
#endif
// Fast move towards endstop until triggered
@ -3120,34 +3132,32 @@ static void homeaxis(const AxisEnum axis) {
const bool pos_dir = axis_home_dir > 0;
#if ENABLED(X_DUAL_ENDSTOPS)
if (axis == X_AXIS) {
const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0);
const float adj = ABS(endstops.x_endstop_adj);
if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
if (pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
if (lock_x1) stepper.set_x_lock(false); else stepper.set_x2_lock(false);
stepper.set_homing_flag_x(false);
stepper.set_x_lock(false);
stepper.set_x2_lock(false);
}
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
if (axis == Y_AXIS) {
const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0);
const float adj = ABS(endstops.y_endstop_adj);
if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
if (pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
if (lock_y1) stepper.set_y_lock(false); else stepper.set_y2_lock(false);
stepper.set_homing_flag_y(false);
stepper.set_y_lock(false);
stepper.set_y2_lock(false);
}
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) {
const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0);
const float adj = ABS(endstops.z_endstop_adj);
if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
if (pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
if (lock_z1) stepper.set_z_lock(false); else stepper.set_z2_lock(false);
stepper.set_homing_flag_z(false);
stepper.set_z_lock(false);
stepper.set_z2_lock(false);
}
#endif
stepper.set_homing_dual_axis(false);
#endif
#if IS_SCARA
@ -3191,8 +3201,7 @@ static void homeaxis(const AxisEnum axis) {
// Clear retracted status if homing the Z axis
#if ENABLED(FWRETRACT)
if (axis == Z_AXIS)
fwretract.hop_amount = 0.0;
if (axis == Z_AXIS) fwretract.hop_amount = 0.0;
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
@ -4442,7 +4451,7 @@ void home_all_axes() { gcode_G28(true); }
reset_bed_level();
break;
} // switch(state)
} // switch (state)
if (state == MeshNext) {
SERIAL_PROTOCOLPAIR("MBL G29 point ", MIN(mbl_probe_index, GRID_MAX_POINTS));

View File

@ -562,7 +562,7 @@ void Endstops::update() {
if (dual_hit) { \
_ENDSTOP_HIT(AXIS1, MINMAX); \
/* if not performing home or if both endstops were trigged during homing... */ \
if (!stepper.performing_homing || dual_hit == 0x3) \
if (!stepper.homing_dual_axis || dual_hit == 0x3) \
planner.endstop_triggered(_AXIS(AXIS1)); \
} \
}while(0)

View File

@ -146,8 +146,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupne")
#define MSG_LED_CONTROL _UxGT("LED Nastaveni")
#define MSG_LEDS_ON _UxGT("Svetla Zap")
#define MSG_LEDS_OFF _UxGT("Svetla Vyp")
#define MSG_LEDS _UxGT("Svetla")
#define MSG_LED_PRESETS _UxGT("Svetla Predvolby")
#define MSG_SET_LEDS_RED _UxGT("Cervena")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranzova")

View File

@ -149,8 +149,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupně")
#define MSG_LED_CONTROL _UxGT("LED Nastavení")
#define MSG_LEDS_ON _UxGT("Světla Zap")
#define MSG_LEDS_OFF _UxGT("Světla Vyp")
#define MSG_LEDS _UxGT("Světla")
#define MSG_LED_PRESETS _UxGT("Světla Předvolby")
#define MSG_SET_LEDS_RED _UxGT("Červená")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranžová")

View File

@ -311,8 +311,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Schrittweises UBL")
#define MSG_LED_CONTROL _UxGT("LED Kontrolle")
#define MSG_LEDS_ON _UxGT("Licht an")
#define MSG_LEDS_OFF _UxGT("Licht aus")
#define MSG_LEDS _UxGT("Licht")
#define MSG_LED_PRESETS _UxGT("Licht Einstellungen")
#define MSG_SET_LEDS_RED _UxGT("Rot")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")

View File

@ -371,11 +371,8 @@
#ifndef MSG_LED_CONTROL
#define MSG_LED_CONTROL _UxGT("LED Control")
#endif
#ifndef MSG_LEDS_ON
#define MSG_LEDS_ON _UxGT("Lights On")
#endif
#ifndef MSG_LEDS_OFF
#define MSG_LEDS_OFF _UxGT("Lights Off")
#ifndef MSG_LEDS
#define MSG_LEDS _UxGT("Lights")
#endif
#ifndef MSG_LED_PRESETS
#define MSG_LED_PRESETS _UxGT("Light Presets")

View File

@ -142,8 +142,7 @@
//#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Z-Offset Stopped")
//#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Step-By-Step UBL")
#define MSG_LED_CONTROL _UxGT("LED ezarpenak")
#define MSG_LEDS_ON _UxGT("Argiak piztu")
#define MSG_LEDS_OFF _UxGT("Argiak itzali")
#define MSG_LEDS _UxGT("Argiak")
#define MSG_LED_PRESETS _UxGT("Argi aurrehautaketak")
#define MSG_SET_LEDS_RED _UxGT("Gorria")
#define MSG_SET_LEDS_ORANGE _UxGT("Laranja")

View File

@ -144,8 +144,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Pas a pas")
#define MSG_LED_CONTROL _UxGT("Controle LED")
#define MSG_LEDS_ON _UxGT("Lumiere ON")
#define MSG_LEDS_OFF _UxGT("Lumiere OFF")
#define MSG_LEDS _UxGT("Lumiere")
#define MSG_LED_PRESETS _UxGT("Preregl. LED.")
#define MSG_SET_LEDS_RED _UxGT("Rouge")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")

View File

@ -145,8 +145,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Pas à pas")
#define MSG_LED_CONTROL _UxGT("Contrôle LED")
#define MSG_LEDS_ON _UxGT("Lumière ON")
#define MSG_LEDS_OFF _UxGT("Lumière OFF")
#define MSG_LEDS _UxGT("Lumière")
#define MSG_LED_PRESETS _UxGT("Préregl. LED")
#define MSG_SET_LEDS_RED _UxGT("Rouge")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")

View File

@ -144,8 +144,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo passo")
#define MSG_LED_CONTROL _UxGT("Controllo LED")
#define MSG_LEDS_ON _UxGT("Luci On")
#define MSG_LEDS_OFF _UxGT("Luci Off")
#define MSG_LEDS _UxGT("Luci")
#define MSG_LED_PRESETS _UxGT("Preset luci")
#define MSG_SET_LEDS_RED _UxGT("Rosso")
#define MSG_SET_LEDS_ORANGE _UxGT("Arancione")

View File

@ -145,8 +145,7 @@
#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Compensacao Z parou")
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo a passo")
#define MSG_LED_CONTROL _UxGT("Controle do LED")
#define MSG_LEDS_ON _UxGT("Luz Acesa")
#define MSG_LEDS_OFF _UxGT("Luz Apagada")
#define MSG_LEDS _UxGT("Luz")
#define MSG_LED_PRESETS _UxGT("Configuracao da Luz")
#define MSG_SET_LEDS_RED _UxGT("Luz Vermelha")
#define MSG_SET_LEDS_ORANGE _UxGT("Luz Laranja")

View File

@ -147,8 +147,7 @@
#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Compensação Z parou")
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo a passo")
#define MSG_LED_CONTROL _UxGT("Controle do LED")
#define MSG_LEDS_ON _UxGT("Luz Acesa")
#define MSG_LEDS_OFF _UxGT("Luz Apagada")
#define MSG_LEDS _UxGT("Luz")
#define MSG_LED_PRESETS _UxGT("Configuração da Luz")
#define MSG_SET_LEDS_RED _UxGT("Luz Vermelha")
#define MSG_SET_LEDS_ORANGE _UxGT("Luz Laranja")

View File

@ -145,8 +145,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Пошаговое UBL")
#define MSG_LED_CONTROL _UxGT("Настройки LED")
#define MSG_LEDS_ON _UxGT("Включить подсветку")
#define MSG_LEDS_OFF _UxGT("Выключить подсветку")
#define MSG_LEDS _UxGT("Подсветку")
#define MSG_LED_PRESETS _UxGT("Предустановки света")
#define MSG_SET_LEDS_RED _UxGT("Красный свет")
#define MSG_SET_LEDS_ORANGE _UxGT("Оранжевый свет")

View File

@ -148,8 +148,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupne")
#define MSG_LED_CONTROL _UxGT("Nastavenie LED")
#define MSG_LEDS_ON _UxGT("Zapnúť svetlo")
#define MSG_LEDS_OFF _UxGT("Vypnúť svetlo")
#define MSG_LEDS _UxGT("Svetlo")
#define MSG_LED_PRESETS _UxGT("Prednastavené farby")
#define MSG_SET_LEDS_RED _UxGT("Červená")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranžová")

View File

@ -141,8 +141,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("一步步UBL") // "Step-By-Step UBL"
#define MSG_LED_CONTROL _UxGT("灯管控制") // "LED Control")
#define MSG_LEDS_ON _UxGT("灯亮") // "Lights On")
#define MSG_LEDS_OFF _UxGT("灯灭") // "Lights Off")
#define MSG_LEDS _UxGT("灯") // "Lights")
#define MSG_LED_PRESETS _UxGT("灯预置") // "Light Presets")
#define MSG_SET_LEDS_RED _UxGT("红") // "Red")
#define MSG_SET_LEDS_ORANGE _UxGT("橙") // "Orange")

View File

@ -141,8 +141,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("一步步UBL") // "Step-By-Step UBL"
#define MSG_LED_CONTROL _UxGT("灯管控制") // "LED Control")
#define MSG_LEDS_ON _UxGT("灯亮") // "Lights On")
#define MSG_LEDS_OFF _UxGT("灯灭") // "Lights Off")
#define MSG_LEDS _UxGT("灯") // "Lights")
#define MSG_LED_PRESETS _UxGT("灯预置") // "Light Presets")
#define MSG_SET_LEDS_RED _UxGT("红") // "Red")
#define MSG_SET_LEDS_ORANGE _UxGT("橙") // "Orange")

View File

@ -76,7 +76,7 @@ Stepper stepper; // Singleton
block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
bool Stepper::performing_homing = false;
bool Stepper::homing_dual_axis = false;
#endif
#if HAS_MOTOR_CURRENT_PWM
@ -153,7 +153,7 @@ bool Stepper::all_steps_done = false;
uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 };
volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
int8_t Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
#if ENABLED(MIXING_EXTRUDER)
int32_t Stepper::counter_m[MIXING_STEPPERS];
@ -170,7 +170,7 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ];
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
#define DUAL_ENDSTOP_APPLY_STEP(A,V) \
if (performing_homing) { \
if (homing_dual_axis) { \
if (A##_HOME_DIR < 0) { \
if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \

View File

@ -86,7 +86,7 @@ class Stepper {
static block_t* current_block; // A pointer to the block currently being traced
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
static bool performing_homing;
static bool homing_dual_axis;
#endif
#if HAS_MOTOR_CURRENT_PWM
@ -164,7 +164,7 @@ class Stepper {
//
// Current direction of stepper motors (+1 or -1)
//
static volatile signed char count_direction[NUM_AXIS];
static int8_t count_direction[NUM_AXIS];
//
// Mixing extruder mix counters
@ -241,18 +241,18 @@ class Stepper {
static void microstep_readings();
#endif
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_dual_axis(const bool state) { homing_dual_axis = state; }
#endif
#if ENABLED(X_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_x(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; }
FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; }
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_y(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; }
FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; }
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
FORCE_INLINE static void set_homing_flag_z(const bool state) { performing_homing = state; }
FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; }
FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; }
#endif

View File

@ -4244,10 +4244,8 @@ void lcd_quick_feedback(const bool clear_buttons) {
void lcd_led_menu() {
START_MENU();
MENU_BACK(MSG_MAIN);
if (leds.lights_on)
MENU_ITEM(function, MSG_LEDS_OFF, leds.toggle);
else
MENU_ITEM(function, MSG_LEDS_ON, leds.toggle);
bool led_on = leds.lights_on;
MENU_ITEM_EDIT_CALLBACK(bool, MSG_LEDS, &led_on, leds.toggle);
MENU_ITEM(function, MSG_SET_LEDS_DEFAULT, leds.set_default);
#if ENABLED(LED_COLOR_PRESETS)
MENU_ITEM(submenu, MSG_LED_PRESETS, lcd_led_presets_menu);

View File

@ -122,10 +122,26 @@
#define U8G_DELAY() u8g_10MicroDelay()
#endif
#define ST7565_CS() { WRITE(ST7565_CS_PIN,1); U8G_DELAY(); }
#define ST7565_NCS() { WRITE(ST7565_CS_PIN,0); }
#define ST7565_A0() { WRITE(ST7565_A0_PIN,1); U8G_DELAY(); }
#define ST7565_NA0() { WRITE(ST7565_A0_PIN,0); }
#define ST7565_CS() do{ WRITE(ST7565_CS_PIN, HIGH); U8G_DELAY(); }while(0)
#define ST7565_NCS() WRITE(ST7565_CS_PIN, LOW)
#define ST7565_A0() do{ WRITE(ST7565_A0_PIN, HIGH); U8G_DELAY(); }while(0)
#define ST7565_NA0() WRITE(ST7565_A0_PIN, LOW)
#define ST7565_ADC_REVERSE(N) ST7565_WRITE_BYTE(0xA0 | ((N) & 0x1))
#define ST7565_BIAS_MODE(N) ST7565_WRITE_BYTE(0xA2 | ((N) & 0x1))
#define ST7565_ALL_PIX(N) ST7565_WRITE_BYTE(0xA4 | ((N) & 0x1))
#define ST7565_INVERTED(N) ST7565_WRITE_BYTE(0xA6 | ((N) & 0x1))
#define ST7565_ON(N) ST7565_WRITE_BYTE(0xAE | ((N) & 0x1))
#define ST7565_OUT_MODE(N) ST7565_WRITE_BYTE(0xC0 | ((N) & 0x1) << 3)
#define ST7565_POWER_CONTROL(N) ST7565_WRITE_BYTE(0x28 | (N))
#define ST7565_V0_RATIO(N) ST7565_WRITE_BYTE(0x20 | ((N) & 0x7))
#define ST7565_CONTRAST(N) do{ ST7565_WRITE_BYTE(0x81); ST7565_WRITE_BYTE(N); }while(0)
#define ST7565_COLUMN_ADR(N) do{ ST7565_WRITE_BYTE(0x10 | ((N) >> 4) & 0xF); ST7565_WRITE_BYTE(0x00 | ((N) & 0xF)); }while(0)
#define ST7565_PAGE_ADR(N) ST7565_WRITE_BYTE(0xB0 | (N))
#define ST7565_START_LINE(N) ST7565_WRITE_BYTE(0x40 | (N))
#define ST7565_SLEEP_MODE() ST7565_WRITE_BYTE(0xAC)
#define ST7565_NOOP() ST7565_WRITE_BYTE(0xE3)
uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
switch (msg) {
@ -137,109 +153,103 @@ uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
OUT_WRITE(ST7565_CLK_PIN, LOW);
#if HARDWARE_SPI
OUT_WRITE(SDSS, 1); // must be set to an output first or else will never go into master mode
SPCR = 0x50; // enable SPI in master mode at fast speed
SPSR = 1; // kick it up to 2x speed mode
OUT_WRITE(SDSS, 1); // must be set to an output first or else will never go into master mode
SPCR = 0x50; // enable SPI in master mode at fast speed
SPSR = 1; // kick it up to 2x speed mode
#endif
OUT_WRITE(ST7565_A0_PIN, LOW);
ST7565_CS(); /* disable chip */
ST7565_NA0(); /* instruction mode */
ST7565_NCS(); /* enable chip */
ST7565_CS(); // chip select off
ST7565_NA0(); // instruction mode
ST7565_NCS(); // chip select
ST7565_WRITE_BYTE(0x0A2); /* 0x0A2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
ST7565_WRITE_BYTE(0x0A0); /* Normal ADC Select (according to Displaytech 64128N datasheet) */
ST7565_BIAS_MODE(0); // 0xA2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
ST7565_ADC_REVERSE(0); // Normal (not flipped) ADC Select (according to Displaytech 64128N datasheet)
ST7565_WRITE_BYTE(0x0C8); /* common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1 */
ST7565_WRITE_BYTE(0x040); /* Display start line for Displaytech 64128N */
ST7565_OUT_MODE(1); // common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1
ST7565_START_LINE(0); // Display start line for Displaytech 64128N
ST7565_WRITE_BYTE(0x028 | 0x04); /* power control: turn on voltage converter */
//U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
//ST7565_POWER_CONTROL(0x4); // power control: turn on Booster
//U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
ST7565_WRITE_BYTE(0x028 | 0x06); /* power control: turn on voltage regulator */
//U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
//ST7565_POWER_CONTROL(0x6); // power control: turn on Booster, Voltage Regulator
//U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
ST7565_WRITE_BYTE(0x028 | 0x07); /* power control: turn on voltage follower */
//U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
ST7565_POWER_CONTROL(0x7); // power control: turn on Booster, Voltage Regulator, Voltage Follower
//U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
ST7565_WRITE_BYTE(0x010); /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
ST7565_V0_RATIO(0); // Set V0 Voltage Resistor ratio. Setting for controlling brightness of Displaytech 64128N
ST7565_WRITE_BYTE(0x0A6); /* display normal, bit val 0: LCD pixel off. */
ST7565_INVERTED(0); // display normal, bit val 0: LCD pixel off.
ST7565_WRITE_BYTE(0x081); /* set contrast */
ST7565_WRITE_BYTE(0x01E); /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
ST7565_CONTRAST(0x1E); // Contrast value. Setting for controlling contrast of Displaytech 64128N
ST7565_WRITE_BYTE(0x0AF); /* display on */
ST7565_ON(1); // display on
U8G_ESC_DLY(100); /* delay 100 ms */
ST7565_WRITE_BYTE(0x0A5); /* display all points; ST7565 */
U8G_ESC_DLY(100); /* delay 100 ms */
U8G_ESC_DLY(100); /* delay 100 ms */
ST7565_WRITE_BYTE(0x0A4); /* normal display */
ST7565_CS(); /* disable chip */
} /* end of sequence */
U8G_ESC_DLY(100); // delay 100 ms
ST7565_ALL_PIX(1); // display all points; ST7565
U8G_ESC_DLY(100); // delay 100 ms
U8G_ESC_DLY(100); // delay 100 ms
ST7565_ALL_PIX(0); // normal display
ST7565_CS(); // chip select off
} // end of sequence
break;
case U8G_DEV_MSG_STOP: break;
case U8G_DEV_MSG_PAGE_NEXT: {
u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
ST7565_CS(); /* disable chip */
ST7565_NA0(); /* instruction mode */
ST7565_NCS(); /* enable chip */
ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
/* end of sequence */
ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page));; /* select current page (ST7565R) */
ST7565_A0(); /* data mode */
ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
ST7565_CS(); /* disable chip */
ST7565_NA0(); /* instruction mode */
ST7565_NCS(); /* enable chip */
ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
/* end of sequence */
ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
ST7565_A0(); /* data mode */
ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
ST7565_CS(); /* disable chip */
u8g_pb_t *pb = (u8g_pb_t*)(dev->dev_mem);
ST7565_CS(); // chip select off
ST7565_NA0(); // instruction mode
ST7565_NCS(); // chip select
ST7565_COLUMN_ADR(0x00); // high 4 bits to 0, low 4 bits to 0. Changed for DisplayTech 64128N
// end of sequence
ST7565_PAGE_ADR(2 * pb->p.page); // select current page (ST7565R)
ST7565_A0(); // data mode
ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)pb->buf);
ST7565_CS(); // chip select off
ST7565_NA0(); // instruction mode
ST7565_NCS(); // chip select
ST7565_COLUMN_ADR(0x00); // high 4 bits to 0, low 4 bits to 0
// end of sequence
ST7565_PAGE_ADR(2 * pb->p.page + 1); // select current page (ST7565R)
ST7565_A0(); // data mode
ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)(pb->buf) + pb->width);
ST7565_CS(); // chip select off
}
break;
case U8G_DEV_MSG_CONTRAST:
ST7565_NCS();
ST7565_NA0(); /* instruction mode */
ST7565_WRITE_BYTE(0x081);
ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
ST7565_CS(); /* disable chip */
ST7565_NA0(); // instruction mode
ST7565_CONTRAST((*(uint8_t*)arg) >> 2);
ST7565_CS(); // chip select off
return 1;
case U8G_DEV_MSG_SLEEP_ON:
ST7565_NA0(); /* instruction mode */
ST7565_NCS(); /* enable chip */
ST7565_WRITE_BYTE(0x0AC); /* static indicator off */
ST7565_WRITE_BYTE(0x000); /* indicator register set (not sure if this is required) */
ST7565_WRITE_BYTE(0x0AE); /* display off */
ST7565_WRITE_BYTE(0x0A5); /* all points on */
ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
/* end of sequence */
ST7565_NA0(); // instruction mode
ST7565_NCS(); // chip select
ST7565_SLEEP_MODE(); // static indicator off
//ST7565_WRITE_BYTE(0x00); // indicator register set (not sure if this is required)
ST7565_ON(0); // display off
ST7565_ALL_PIX(1); // all points on
ST7565_CS(); // chip select off
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
ST7565_NA0(); /* instruction mode */
ST7565_NCS(); /* enable chip */
ST7565_WRITE_BYTE(0x0A4); /* all points off */
ST7565_WRITE_BYTE(0x0AF); /* display on */
U8G_ESC_DLY(50); /* delay 50 ms */
ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
/* end of sequence */
ST7565_NA0(); // instruction mode
ST7565_NCS(); // chip select
ST7565_ALL_PIX(0); // all points off
ST7565_ON(1); // display on
U8G_ESC_DLY(50); // delay 50 ms
ST7565_CS(); // chip select off
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[LCD_PIXEL_WIDTH*2] U8G_NOCOMMON;
uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[LCD_PIXEL_WIDTH * 2] U8G_NOCOMMON;
u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = {{16, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = {u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn};