My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

u8g_state.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. u8g_state.c
  3. backup and restore hardware state
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2011, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. state callback: backup env U8G_STATE_MSG_BACKUP_ENV
  28. device callback: DEV_MSG_INIT
  29. state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G
  30. state callback: restore env U8G_STATE_MSG_RESTORE_ENV
  31. state callback: backup env U8G_STATE_MSG_BACKUP_ENV
  32. state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G
  33. DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT
  34. state callback: restore env U8G_STATE_MSG_RESTORE_ENV
  35. */
  36. #include <stddef.h>
  37. #include "u8g.h"
  38. void u8g_state_dummy_cb(uint8_t msg)
  39. {
  40. /* the dummy procedure does nothing */
  41. }
  42. void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb)
  43. {
  44. u8g->state_cb = backup_cb;
  45. /* in most cases the init message was already sent, so this will backup the */
  46. /* current u8g state */
  47. backup_cb(U8G_STATE_MSG_BACKUP_U8G);
  48. }
  49. /*===============================================================*/
  50. /* AVR */
  51. #if defined(__AVR__)
  52. #define U8G_ATMEGA_HW_SPI
  53. /* remove the definition for attiny */
  54. #if __AVR_ARCH__ == 2
  55. #undef U8G_ATMEGA_HW_SPI
  56. #endif
  57. #if __AVR_ARCH__ == 25
  58. #undef U8G_ATMEGA_HW_SPI
  59. #endif
  60. #endif
  61. #if defined(U8G_ATMEGA_HW_SPI)
  62. #include <avr/interrupt.h>
  63. static uint8_t u8g_state_avr_spi_memory[2];
  64. void u8g_backup_avr_spi(uint8_t msg)
  65. {
  66. if ( U8G_STATE_MSG_IS_BACKUP(msg) )
  67. {
  68. u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR;
  69. }
  70. else
  71. {
  72. uint8_t tmp = SREG;
  73. cli();
  74. SPCR = 0;
  75. SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)];
  76. SREG = tmp;
  77. }
  78. }
  79. #endif