├── .gitignore ├── Datasheets ├── AtMega128.pdf ├── AtMega128Migration.pdf ├── Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf ├── CricutCartridgeBottom.jpg ├── CricutCartridgeTop.jpg ├── CricutCartridgeTop2.jpg ├── CricutExpressionHardware.pdf ├── CricutExpressionISP.jpg ├── CricutExpressionJtag.jpg ├── CricutMemoryCrd.svg ├── CricutPersonalHardware.pdf └── OLED_2_7_12864.txt ├── Docs ├── GP-GL.pdf ├── HP-GL.pdf └── OLED Display Designer.xlsx ├── LICENSE ├── README.MD └── src ├── .vs └── FreeExpression │ └── v14 │ └── .atsuo ├── Connector pinout.txt ├── Debug ├── Makefile └── makedep.mk ├── FreeExpression.atsln ├── FreeExpression.atsuo ├── FreeExpression.componentinfo.xml ├── FreeExpression.cproj ├── FreeExpression.cproj.bak ├── FreeExpression_6_2.atsln ├── FreeExpression_6_2.cproj ├── Makefile ├── README.MD ├── avrlib.h ├── avrlibdefs.h ├── avrlibtypes.h ├── cli.c ├── cli.h ├── configs.h ├── dial.c ├── dial.h ├── display.c ├── display.h ├── display_lcd.c ├── display_lcd.h ├── display_oled.c ├── display_oled.h ├── flash.c ├── flash.h ├── g_code.c ├── g_code.h ├── hackNotes.PDF ├── hpgl.c ├── hpgl.h ├── keybad_expression.c ├── keypad.c ├── keypad.c.bak ├── keypad.h ├── keypad_cake.h ├── keypad_expression.h ├── m2u8 ├── Debug │ ├── Makefile │ └── makedep.mk ├── m2u8.componentinfo.xml ├── m2u8.cproj ├── m2u8_6_2.cproj ├── u8g.h ├── u8g_bitmap.c ├── u8g_circle.c ├── u8g_clip.c ├── u8g_com_api.c ├── u8g_com_api_16gr.c ├── u8g_com_arduino_attiny85_hw_spi.c ├── u8g_com_arduino_common.c ├── u8g_com_arduino_fast_parallel.c ├── u8g_com_arduino_hw_spi.c ├── u8g_com_arduino_hw_usart_spi.c ├── u8g_com_arduino_no_en_parallel.c ├── u8g_com_arduino_parallel.c ├── u8g_com_arduino_port_d_wr.c ├── u8g_com_arduino_ssd_i2c.c ├── u8g_com_arduino_st7920_custom.c ├── u8g_com_arduino_st7920_hw_spi.c ├── u8g_com_arduino_st7920_spi.c ├── u8g_com_arduino_std_sw_spi.c ├── u8g_com_arduino_sw_spi.c ├── u8g_com_arduino_t6963.c ├── u8g_com_arduino_uc_i2c.c ├── u8g_com_atmega_hw_spi.c ├── u8g_com_atmega_parallel.c ├── u8g_com_atmega_st7920_hw_spi.c ├── u8g_com_atmega_st7920_spi.c ├── u8g_com_atmega_sw_spi.c ├── u8g_com_i2c.c ├── u8g_com_io.c ├── u8g_com_null.c ├── u8g_com_raspberrypi_hw_spi.c ├── u8g_com_raspberrypi_ssd_i2c.c ├── u8g_cursor.c ├── u8g_delay.c ├── u8g_dev_a2_micro_printer.c ├── u8g_dev_flipdisc_2x7.c ├── u8g_dev_gprof.c ├── u8g_dev_ht1632.c ├── u8g_dev_ili9325d_320x240.c ├── u8g_dev_ks0108_128x64.c ├── u8g_dev_lc7981_160x80.c ├── u8g_dev_lc7981_240x128.c ├── u8g_dev_lc7981_240x64.c ├── u8g_dev_lc7981_320x64.c ├── u8g_dev_ld7032_60x32.c ├── u8g_dev_null.c ├── u8g_dev_pcd8544_84x48.c ├── u8g_dev_pcf8812_96x65.c ├── u8g_dev_sbn1661_122x32.c ├── u8g_dev_ssd1306_128x32.c ├── u8g_dev_ssd1306_128x64.c ├── u8g_dev_ssd1309_128x64.c ├── u8g_dev_ssd1322_nhd31oled_bw.c ├── u8g_dev_ssd1322_nhd31oled_gr.c ├── u8g_dev_ssd1325_nhd27oled_bw.c ├── u8g_dev_ssd1325_nhd27oled_bw_new.c ├── u8g_dev_ssd1325_nhd27oled_gr.c ├── u8g_dev_ssd1325_nhd27oled_gr_new.c ├── u8g_dev_ssd1327_96x96_gr.c ├── u8g_dev_ssd1351_128x128.c ├── u8g_dev_st7565_64128n.c ├── u8g_dev_st7565_dogm128.c ├── u8g_dev_st7565_dogm132.c ├── u8g_dev_st7565_lm6059.c ├── u8g_dev_st7565_lm6063.c ├── u8g_dev_st7565_nhd_c12832.c ├── u8g_dev_st7565_nhd_c12864.c ├── u8g_dev_st7687_c144mvgd.c ├── u8g_dev_st7920_128x64.c ├── u8g_dev_st7920_192x32.c ├── u8g_dev_st7920_202x32.c ├── u8g_dev_t6963_128x128.c ├── u8g_dev_t6963_128x64.c ├── u8g_dev_t6963_240x128.c ├── u8g_dev_t6963_240x64.c ├── u8g_dev_tls8204_84x48.c ├── u8g_dev_uc1601_c128032.c ├── u8g_dev_uc1608_240x128.c ├── u8g_dev_uc1608_240x64.c ├── u8g_dev_uc1610_dogxl160.c ├── u8g_dev_uc1611_dogm240.c ├── u8g_dev_uc1611_dogxl240.c ├── u8g_dev_uc1701_dogs102.c ├── u8g_dev_uc1701_mini12864.c ├── u8g_ellipse.c ├── u8g_font.c ├── u8g_font_data.c ├── u8g_line.c ├── u8g_ll_api.c ├── u8g_page.c ├── u8g_pb.c ├── u8g_pb14v1.c ├── u8g_pb16h1.c ├── u8g_pb16h2.c ├── u8g_pb16v1.c ├── u8g_pb16v2.c ├── u8g_pb32h1.c ├── u8g_pb8h1.c ├── u8g_pb8h1f.c ├── u8g_pb8h2.c ├── u8g_pb8h8.c ├── u8g_pb8v1.c ├── u8g_pb8v2.c ├── u8g_pbxh16.c ├── u8g_pbxh24.c ├── u8g_polygon.c ├── u8g_rect.c ├── u8g_rot.c ├── u8g_scale.c ├── u8g_state.c ├── u8g_u16toa.c ├── u8g_u8toa.c └── u8g_virtual_screen.c ├── main.c ├── scale.c ├── scale.h ├── serial.c ├── serial.h ├── shvars.c ├── shvars.h ├── spi.c ├── spi.h ├── stepper.c ├── stepper.c.bak ├── stepper.h ├── timer.c ├── timer.h ├── usb.c ├── usb.h └── version.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.d 4 | *.lss 5 | *.srec 6 | *.eep 7 | *.ko 8 | *.obj 9 | *.elf 10 | 11 | # Precompiled Headers 12 | *.gch 13 | *.pch 14 | 15 | # Libraries 16 | *.lib 17 | *.a 18 | *.la 19 | *.lo 20 | 21 | # Shared objects (inc. Windows DLLs) 22 | *.dll 23 | *.so 24 | *.so.* 25 | *.dylib 26 | 27 | # Executables 28 | *.exe 29 | *.out 30 | *.app 31 | *.i*86 32 | *.x86_64 33 | *.hex 34 | -------------------------------------------------------------------------------- /Datasheets/AtMega128.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/AtMega128.pdf -------------------------------------------------------------------------------- /Datasheets/AtMega128Migration.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/AtMega128Migration.pdf -------------------------------------------------------------------------------- /Datasheets/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf -------------------------------------------------------------------------------- /Datasheets/CricutCartridgeBottom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutCartridgeBottom.jpg -------------------------------------------------------------------------------- /Datasheets/CricutCartridgeTop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutCartridgeTop.jpg -------------------------------------------------------------------------------- /Datasheets/CricutCartridgeTop2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutCartridgeTop2.jpg -------------------------------------------------------------------------------- /Datasheets/CricutExpressionHardware.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutExpressionHardware.pdf -------------------------------------------------------------------------------- /Datasheets/CricutExpressionISP.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutExpressionISP.jpg -------------------------------------------------------------------------------- /Datasheets/CricutExpressionJtag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutExpressionJtag.jpg -------------------------------------------------------------------------------- /Datasheets/CricutPersonalHardware.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Datasheets/CricutPersonalHardware.pdf -------------------------------------------------------------------------------- /Docs/GP-GL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Docs/GP-GL.pdf -------------------------------------------------------------------------------- /Docs/HP-GL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Docs/HP-GL.pdf -------------------------------------------------------------------------------- /Docs/OLED Display Designer.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/Docs/OLED Display Designer.xlsx -------------------------------------------------------------------------------- /src/.vs/FreeExpression/v14/.atsuo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/src/.vs/FreeExpression/v14/.atsuo -------------------------------------------------------------------------------- /src/Connector pinout.txt: -------------------------------------------------------------------------------- 1 | // This file documents the pinout of the connectors and the modifications required for JTAG and SPI LCD hookup 2 | /* LCD connector -- see also LCD.c 3 | *J1 Pin| LCD Pin | AVR,pin Original connection 4 | *------+--------------+----------------------------------- 5 | * 1 | GND, 1 | | 6 | * 2 | Vcc, 2 | 5v | 7 | * 3 | MOSI,(R/W),5| PB2,MOSI,12, | PF5, (TMS,56), cut trace 8 | * 4 | C,(RS),4 | PB5,15 | PF6, (TDO,55), cut trace 9 | * 5 | MISO,(D0),7 | PB3,MISO,13 | PF7, (TDI,54), cut trace 10 | * 6 | NC | PE4 | 11 | * 7 | NC | PE5 | 12 | * 8 | NC | PE6 | 13 | * 9 | RES,16 | PE7 | 14 | * 10 | SCK,(E),6 | PB1,SCK,11 | PF4 via R28 and Q2 (TCK,57), cut trace. was LCD backlight and Dial power, switched via R28, Q2, PF4 now used as JTAG TCK on J5 pin 10 15 | * ---------------------------------------------- 16 | * 17 | * J5, JTAG and serial programming and debugging 18 | * J5 | | |AVR 19 | * pin |Func. |via |pin | components removed or trace cut 20 | * ----+-------+-------+-------+-------------- 21 | * 1 |PDO | |3 | 22 | * 2 |VCC |R11 |52 | 23 | * 3 |SCK |R9 |11 | -- Also connects to U1 pin 2 (SCK) 24 | * 4 |PDI |R12 |2 | 25 | * 5 |RESETn |R15 |20 | 26 | * 6 |GND |direct |22 | 27 | * 7 |TMS |direct |56 |R24 removed 28 | * 8 |TDI |direct |54 |R13 removed 29 | * 9 |TDO |direct |55 |R14 removed 30 | * 10 |TCK |direct |57 | cut trace on R28, 820ohms 31 | * --------------------------------------------- 32 | */ 33 | -------------------------------------------------------------------------------- /src/Debug/makedep.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit or delete the file 3 | ################################################################################ 4 | 5 | cli.c 6 | 7 | dial.c 8 | 9 | display.c 10 | 11 | display_oled.c 12 | 13 | flash.c 14 | 15 | g_code.c 16 | 17 | hpgl.c 18 | 19 | keypad.c 20 | 21 | display_lcd.c 22 | 23 | main.c 24 | 25 | scale.c 26 | 27 | serial.c 28 | 29 | shvars.c 30 | 31 | spi.c 32 | 33 | stepper.c 34 | 35 | timer.c 36 | 37 | usb.c 38 | 39 | -------------------------------------------------------------------------------- /src/FreeExpression.atsln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Atmel Studio Solution File, Format Version 11.00 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "FreeExpression", "FreeExpression.cproj", "{2DB61C7E-70C7-4213-B96E-2337EC078BE2}" 7 | ProjectSection(ProjectDependencies) = postProject 8 | {667928C5-69CD-44DA-9947-B8268EAA0738} = {667928C5-69CD-44DA-9947-B8268EAA0738} 9 | EndProjectSection 10 | EndProject 11 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "m2u8", "m2u8\m2u8.cproj", "{667928C5-69CD-44DA-9947-B8268EAA0738}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|AVR = Debug|AVR 16 | Release|AVR = Release|AVR 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Debug|AVR.ActiveCfg = Debug|AVR 20 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Debug|AVR.Build.0 = Debug|AVR 21 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Release|AVR.ActiveCfg = Release|AVR 22 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Release|AVR.Build.0 = Release|AVR 23 | {667928C5-69CD-44DA-9947-B8268EAA0738}.Debug|AVR.ActiveCfg = Debug|AVR 24 | {667928C5-69CD-44DA-9947-B8268EAA0738}.Debug|AVR.Build.0 = Debug|AVR 25 | {667928C5-69CD-44DA-9947-B8268EAA0738}.Release|AVR.ActiveCfg = Release|AVR 26 | {667928C5-69CD-44DA-9947-B8268EAA0738}.Release|AVR.Build.0 = Release|AVR 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /src/FreeExpression.atsuo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/src/FreeExpression.atsuo -------------------------------------------------------------------------------- /src/FreeExpression.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom1281.h 30 | 31 | header 32 | C 33 | gp4852szaErIVeiiC0MhRg== 34 | 35 | include/avr/iom1281.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.c 41 | template 42 | source 43 | C Exe 44 | GD1k8YYhulqRs6FD1B2Hog== 45 | 46 | templates/main.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\main.cpp 52 | template 53 | source 54 | C Exe 55 | YXFphlh0CtZJU+ebktABgQ== 56 | 57 | templates/main.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega1281 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega1281 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega1281 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/FreeExpression_6_2.atsln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Atmel Studio Solution File, Format Version 11.00 4 | Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "FreeExpression", "FreeExpression_6_2.cproj", "{2DB61C7E-70C7-4213-B96E-2337EC078BE2}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|AVR = Debug|AVR 9 | Release|AVR = Release|AVR 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Debug|AVR.ActiveCfg = Debug|AVR 13 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Debug|AVR.Build.0 = Debug|AVR 14 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Release|AVR.ActiveCfg = Release|AVR 15 | {2DB61C7E-70C7-4213-B96E-2337EC078BE2}.Release|AVR.Build.0 = Release|AVR 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # Freecut: open firmware for Cricut Expression 1 devices. 2 | # 3 | # 4 | # MCU name 5 | MCU = atmega1281 6 | 7 | # Output format. (can be srec, ihex) 8 | FORMAT = ihex 9 | 10 | # Target file name (without extension). 11 | TARGET = freecut 12 | 13 | # Speed 14 | FCLK = 16000000UL 15 | 16 | # List C source files here. (C dependencies are automatically generated.) 17 | SRC = main.c usb.c lcd.c keypad.c timer.c stepper.c cli.c flash.c dial.c hpgl.c shvars.c scale.c 18 | 19 | # Assembler sources 20 | ASRC = 21 | 22 | # Optional compiler flags. 23 | CFLAGS = -D$(MCU) $(TEST) $(CE) -Os -DFCLK=$(FCLK) -fpack-struct 24 | CFLAGS += -fshort-enums -Wall -Werror -Wstrict-prototypes 25 | 26 | # Optional assembler flags. 27 | ASFLAGS = -Wa,-ahlms=$(<:.S=.lst),-gstabs 28 | 29 | # Optional linker flags. 30 | LDFLAGS = -Wl,-Map=$(TARGET).map,--cref 31 | 32 | # Additional libraries 33 | # 34 | # Minimalistic printf version 35 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_min 36 | # 37 | # Floating point printf version (requires -lm below) 38 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt 39 | # 40 | # -lm = math library 41 | LDFLAGS += -lm 42 | 43 | # --------------------------------------------------------------------------- 44 | 45 | # Define directories, if needed. 46 | 47 | # Define programs and commands. 48 | SHELL = sh 49 | 50 | CC = avr-gcc 51 | 52 | OBJCOPY = avr-objcopy 53 | OBJDUMP = avr-objdump 54 | 55 | # Define all object files. 56 | OBJ = $(ASRC:.S=.o) $(SRC:.c=.o) 57 | 58 | # Define all listing files. 59 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) 60 | 61 | # Combine all necessary flags and optional flags. Add target processor to flags. 62 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) 63 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) 64 | 65 | # Default target. 66 | all: $(TARGET).elf $(TARGET).hex $(TARGET).lss tags 67 | 68 | .PHONY: prog 69 | 70 | #you may need to change this line to program your device 71 | prog: all 72 | avrdude -pm128 -cstk500v2 -b115200 -P/dev/ttyUSB0 -u -V -U flash:w:$(TARGET).hex:i 73 | 74 | # Create final output files (.hex) from ELF output file. 75 | %.hex: %.elf 76 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ 77 | 78 | # Disassembly listing 79 | %.dis: %.elf 80 | $(OBJDUMP) -d $< > $@ 81 | 82 | # Create extended listing file from ELF output file. 83 | %.lss: %.elf 84 | $(OBJDUMP) -h -S $< > $@ 85 | 86 | # Link: create ELF output file from object files. 87 | .SECONDARY : $(TARGET).elf 88 | .PRECIOUS : $(OBJ) 89 | %.elf: $(OBJ) 90 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) 91 | 92 | 93 | # Compile: create object files from C source files. 94 | %.o : %.c 95 | $(CC) -c $(ALL_CFLAGS) $< -o $@ 96 | 97 | 98 | # Compile: create assembler files from C source files. 99 | %.s : %.c 100 | $(CC) -S $(ALL_CFLAGS) $< -o $@ 101 | 102 | 103 | # Assemble: create object files from assembler source files. 104 | %.o : %.S 105 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ 106 | 107 | 108 | # Target: clean project. 109 | 110 | clean : 111 | rm -f *.hex 112 | rm -f *.obj 113 | rm -f *.elf 114 | rm -f *.map 115 | rm -f *.obj 116 | rm -f *.sym 117 | rm -f *.ssm 118 | rm -f *.lnk 119 | rm -f *.lss 120 | rm -f *.lst 121 | rm -f $(OBJ) 122 | rm -f $(LST) 123 | rm -f $(SRC:.c=.s) 124 | rm -f $(SRC:.c=.d) 125 | rm -f logfile 126 | 127 | 128 | # Automatically generate C source code dependencies. 129 | # (Code originally taken from the GNU make user manual and modified (See README.txt Credits).) 130 | # Note that this will work with sh (bash) and sed that is shipped with WinAVR (see the SHELL variable defined above). 131 | # This may not work with other shells or other seds. 132 | %.d: %.c 133 | set -e; $(CC) -MM $(ALL_CFLAGS) $< \ 134 | | sed -e 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' \ 135 | > $@; [ -s $@ ] || rm -f $@ 136 | 137 | 138 | # Remove the '-' if you want to see the dependency files generated. 139 | -include $(SRC:.c=.d) 140 | 141 | 142 | # Listing of phony targets. 143 | .PHONY : all clean 144 | 145 | tags: *.[hc] 146 | ctags *.[hc] 147 | 148 | 149 | -------------------------------------------------------------------------------- /src/avrlib.h: -------------------------------------------------------------------------------- 1 | /*! \file global.h \brief AVRlib project global include. */ 2 | //***************************************************************************** 3 | // 4 | // File Name : 'global.h' 5 | // Title : AVRlib project global include 6 | // Author : Pascal Stang - Copyright (C) 2001-2002 7 | // Created : 7/12/2001 8 | // Revised : 9/30/2002 9 | // Version : 1.1 10 | // Target MCU : Atmel AVR series 11 | // Editor Tabs : 4 12 | // 13 | // Description : This include file is designed to contain items useful to all 14 | // code files and projects. 15 | // 16 | // This code is distributed under the GNU Public License 17 | // which can be found at http://www.gnu.org/licenses/gpl.txt 18 | // 19 | //***************************************************************************** 20 | 21 | #ifndef GLOBAL_H 22 | #define GLOBAL_H 23 | 24 | // global AVRLIB defines 25 | #include "avrlibdefs.h" 26 | // global AVRLIB types definitions 27 | #include "avrlibtypes.h" 28 | 29 | // project/system dependent defines 30 | 31 | // CPU clock speed -- defined Project wide vi a -DF_CPU on the command line 32 | #ifndef F_CPU 33 | #define F_CPU 16000000 // 16MHz processor 34 | #endif 35 | //#define F_CPU 14745000 // 14.745MHz processor 36 | //#define F_CPU 8000000 // 8MHz processor 37 | //#define F_CPU 7372800 // 7.37MHz processor 38 | //#define F_CPU 4000000 // 4MHz processor 39 | //#define F_CPU 3686400 // 3.69MHz processor 40 | #define CYCLES_PER_US ((F_CPU+500000)/1000000) // cpu cycles per microsecond 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /src/avrlibdefs.h: -------------------------------------------------------------------------------- 1 | /*! \file avrlibdefs.h \brief AVRlib global defines and macros. */ 2 | //***************************************************************************** 3 | // 4 | // File Name : 'avrlibdefs.h' 5 | // Title : AVRlib global defines and macros include file 6 | // Author : Pascal Stang 7 | // Created : 7/12/2001 8 | // Revised : 9/30/2002 9 | // Version : 1.1 10 | // Target MCU : Atmel AVR series 11 | // Editor Tabs : 4 12 | // 13 | // Description : This include file is designed to contain items useful to all 14 | // code files and projects, regardless of specific implementation. 15 | // 16 | // This code is distributed under the GNU Public License 17 | // which can be found at http://www.gnu.org/licenses/gpl.txt 18 | // 19 | //***************************************************************************** 20 | 21 | 22 | #ifndef AVRLIBDEFS_H 23 | #define AVRLIBDEFS_H 24 | 25 | // Code compatibility to new AVR-libc 26 | // outb(), inb(), inw(), outw(), BV(), sbi(), cbi(), sei(), cli() 27 | #ifndef outb 28 | #define outb(addr, data) addr = (data) 29 | #endif 30 | #ifndef inb 31 | #define inb(addr) (addr) 32 | #endif 33 | #ifndef outw 34 | #define outw(addr, data) addr = (data) 35 | #endif 36 | #ifndef inw 37 | #define inw(addr) (addr) 38 | #endif 39 | #ifndef BV 40 | #define BV(bit) (1<<(bit)) 41 | #endif 42 | #ifndef cbi 43 | #define cbi(reg,bit) reg &= ~(BV(bit)) 44 | #endif 45 | #ifndef sbi 46 | #define sbi(reg,bit) reg |= (BV(bit)) 47 | #endif 48 | #ifndef cli 49 | #define cli() __asm__ __volatile__ ("cli" ::) 50 | #endif 51 | #ifndef sei 52 | #define sei() __asm__ __volatile__ ("sei" ::) 53 | #endif 54 | 55 | // support for individual port pin naming in the mega128 56 | // see port128.h for details 57 | #ifdef __AVR_ATmega128__ 58 | // not currently necessary due to inclusion 59 | // of these defines in newest AVR-GCC 60 | // do a quick test to see if include is needed 61 | #ifndef PD0 62 | #include "port128.h" 63 | #endif 64 | #endif 65 | 66 | // use this for packed structures 67 | // (this is seldom necessary on an 8-bit architecture like AVR, 68 | // but can assist in code portability to AVR) 69 | #define GNUC_PACKED __attribute__((packed)) 70 | 71 | // port address helpers 72 | #define DDR(x) ((x)-1) // address of data direction register of port x 73 | #define PIN(x) ((x)-2) // address of input register of port x 74 | 75 | // MIN/MAX/ABS macros 76 | #define MIN(a,b) ((ab)?(a):(b)) 78 | #define ABS(x) ((x>0)?(x):(-x)) 79 | 80 | // constants 81 | #define PI 3.14159265359 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/avrlibtypes.h: -------------------------------------------------------------------------------- 1 | /*! \file avrlibtypes.h \brief AVRlib global types and typedefines. */ 2 | //***************************************************************************** 3 | // 4 | // File Name : 'avrlibtypes.h' 5 | // Title : AVRlib global types and typedefines include file 6 | // Author : Pascal Stang 7 | // Created : 7/12/2001 8 | // Revised : 9/30/2002 9 | // Version : 1.0 10 | // Target MCU : Atmel AVR series 11 | // Editor Tabs : 4 12 | // 13 | // Description : Type-defines required and used by AVRlib. Most types are also 14 | // generally useful. 15 | // 16 | // This code is distributed under the GNU Public License 17 | // which can be found at http://www.gnu.org/licenses/gpl.txt 18 | // 19 | //***************************************************************************** 20 | 21 | 22 | #ifndef AVRLIBTYPES_H 23 | #define AVRLIBTYPES_H 24 | 25 | #ifndef WIN32 26 | // true/false defines 27 | #define FALSE 0 28 | #define TRUE -1 29 | #endif 30 | 31 | // datatype definitions macros 32 | typedef unsigned char u08; 33 | typedef signed char s08; 34 | typedef unsigned short u16; 35 | typedef signed short s16; 36 | typedef unsigned long u32; 37 | typedef signed long s32; 38 | typedef unsigned long long u64; 39 | typedef signed long long s64; 40 | 41 | /* use inttypes.h instead 42 | // C99 standard integer type definitions 43 | typedef unsigned char uint8_t; 44 | typedef signed char int8_t; 45 | typedef unsigned short uint16_t; 46 | typedef signed short int16_t; 47 | typedef unsigned long uint32_t; 48 | typedef signed long int32_t; 49 | typedef unsigned long uint64_t; 50 | typedef signed long int64_t; 51 | */ 52 | // maximum value that can be held 53 | // by unsigned data types (8,16,32bits) 54 | #define MAX_U08 255 55 | #define MAX_U16 65535 56 | #define MAX_U32 4294967295 57 | 58 | // maximum values that can be held 59 | // by signed data types (8,16,32bits) 60 | #define MIN_S08 -128 61 | #define MAX_S08 127 62 | #define MIN_S16 -32768 63 | #define MAX_S16 32767 64 | #define MIN_S32 -2147483648 65 | #define MAX_S32 2147483647 66 | 67 | #ifndef WIN32 68 | // more type redefinitions 69 | typedef unsigned char BOOL; 70 | typedef unsigned char BYTE; 71 | typedef unsigned int WORD; 72 | typedef unsigned long DWORD; 73 | 74 | typedef unsigned char UCHAR; 75 | typedef unsigned int UINT; 76 | typedef unsigned short USHORT; 77 | typedef unsigned long ULONG; 78 | 79 | typedef char CHAR; 80 | typedef int INT; 81 | typedef long LONG; 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /src/cli.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cli.c 3 | * 4 | * command line interface 5 | * 6 | * Passes data to the Language parser & interprets the results 7 | * 8 | * TODO: Re-implement scaling 9 | * TODO: Implement store - or - cut feature 10 | * TODO: Implement retrieve and cut feature 11 | * 12 | * This file is part of FreeExpression. 13 | * 14 | * https://github.com/thetazzbot/FreeExpression 15 | * 16 | * FreeExpression is free software: you can redistribute it and/or modify it 17 | * under the terms of the GNU General Public License version 2. 18 | * 19 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 20 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 21 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 22 | * License for more details. 23 | * 24 | * You should have received a copy of the GNU General Public License 25 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include "timer.h" 40 | #include "cli.h" 41 | #include "usb.h" 42 | #include "stepper.h" 43 | #include "version.h" 44 | #include "shvars.h" 45 | #include "hpgl.h" 46 | #include "g_code.h" 47 | #include "display.h" 48 | #include "keypad.h" 49 | void cli_poll(void) 50 | { 51 | STEPPER_COORD dstx, dsty; 52 | char c; 53 | int8_t cmd; 54 | uint8_t labelchar; 55 | 56 | 57 | while((c = (char)usb_getc())!=SERIAL_NO_DATA) 58 | { 59 | switch(Lang) 60 | { 61 | case HPGL: 62 | cmd = hpgl_char(c, &dstx, &dsty, &labelchar); 63 | break; 64 | 65 | case G_CODE: 66 | cmd = gcode_char(c, &dstx, &dsty ); 67 | break; 68 | 69 | //case GPGL: 70 | // TODO 71 | //break; 72 | 73 | default: 74 | continue; // just consume everything and do nothing 75 | 76 | } 77 | 78 | 79 | switch(cmd) 80 | { 81 | case CMD_PU: 82 | //sprintf(s,"PU: %d %d",dstx,dsty); 83 | //display_puts( s); 84 | if (dstx >= 0 && dsty >= 0) // filter out illegal moves 85 | stepper_move( dstx, dsty ); 86 | break; 87 | case CMD_PD: 88 | //sprintf(s,"PD: %d %d",dstx,dsty); 89 | // display_puts( s); 90 | if (dstx >= 0 && dsty >= 0) // filter out illegal moves 91 | stepper_draw( dstx, dsty ); 92 | break; 93 | 94 | case CMD_INIT: 95 | // 1. home 96 | // 2. init scale etc 97 | // typically happens at start and end of each document; 98 | dstx = dsty = 0; 99 | // sprintf(s,"IN: %d %d",dstx,dsty); 100 | //display_puts( s); 101 | stepper_move( dstx, dsty ); 102 | break; 103 | case CMD_SEEK0: 104 | //sprintf(s,"SK: %d %d",dstx,dsty); 105 | //display_puts( s); 106 | stepper_move( dstx, dsty ); 107 | break; 108 | #ifdef non_supported_commands 109 | case CMD_PA: // not supported 110 | break; 111 | case CMD_ARCABS: // not supported 112 | //arc_active = arc_init(); 113 | break; 114 | case CMD_LB0: // not supported 115 | // text_beginlabel(); 116 | break; 117 | case CMD_LB: // not supported 118 | // if (labelchar != 0) { 119 | // char_active = text_char(labelchar, &dstx, &dsty, &penny); 120 | // } 121 | 122 | break; 123 | case CMD_SI: // not supported 124 | //text_scale_cm(numpad[0], numpad[1]); 125 | break; 126 | case CMD_SR: // not supported 127 | //text_scale_rel(numpad[0], numpad[1]); 128 | break; 129 | case CMD_DI: // not supported 130 | //text_direction(numpad[0], numpad[1]); 131 | break; 132 | //case CMD_FS: 133 | // stepper_pressure(numpad[0]*100); 134 | // break; 135 | case CMD_VS: 136 | //sprintf(s,"VS: %d",(int)numpad[0]); 137 | //display_puts( s); 138 | // stepper_speed(numpad[0]); 139 | break; 140 | case CMD_AS: // acceleration not supported 141 | //set_acceleration_mode(numpad[0]); 142 | break; 143 | #endif 144 | default: 145 | break; 146 | } 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/cli.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cli.h 3 | * 4 | * This file is part of FreeExpression. 5 | * 6 | * https://github.com/thetazzbot/FreeExpression 7 | * 8 | * FreeExpression is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2. 10 | * 11 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 18 | * 19 | */ 20 | #ifndef cli_h 21 | #define cli_h 22 | 23 | void cli_poll( void ); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /src/configs.h: -------------------------------------------------------------------------------- 1 | ///\file configs.h 2 | /// 3 | /// This is where global parameters such as scale coefficients and step paces are defined. 4 | /// This file is part of grbl and the scale code and not all options are used 5 | /// 6 | #ifndef _CONFIGS_H 7 | #define _CONFIGS_H 8 | #define DEBUG_KEYBOARD // define to display keycode values on the display for debugging key mapping header files 9 | 10 | #define NO_MAD_ACCEL //!< gobsmackingly fast mode for little to none precision 11 | #define NO_SLOW_QUALITY //!< painstakingly slow mode for extra precision, maybe 12 | #define NO_YSKIPPY //!< YSKIPPY makes extra pace by skipping every 4th step on Y axis 13 | 14 | // fast speeds 15 | // x=40 is okay for small Y's, but even 80 is too fast for the far side 16 | // y=80 is generally fine 17 | // 18 | // for prescaler / 256 19 | #define MOTOR_PACE_SLOW 0x60 //!< both motors start at slow pace 20 | #define MOTOR_PACE_FASTX 0x20 //!< X axis has smaller steps, goes faster 21 | #define MOTOR_PACE_FASTY 0x20 //!< Y axis has larger steps, goes slower 22 | // for prescaler / 64 23 | //#define MOTOR_PACE_SLOW 0xff //!< both motors start at slow pace 24 | //#define MOTOR_PACE_FASTX 0x40 //!< X axis has smaller steps, goes faster 25 | //#define MOTOR_PACE_FASTY 0x60 //!< Y axis has larger steps, goes slower 26 | 27 | #define ACCEL_STEPS_RAMP 3 //!< ramp up/down each this many steps 28 | 29 | #define ACCEL_XTHRESH1 800 30 | #define ACCEL_XTHRESH2 1600 31 | 32 | #define STEPSCALE_X 1.8989 //!< scale coefficient X 33 | #define STEPSCALE_Y 0.7588 //!< scale coefficient Y 34 | 35 | #define SLEEP_PERIOD 256 //!< clk/256/256 36 | #define SLEEP_COUNTER 5 //!< this many periods of inactivity and we really go zZz 37 | 38 | #define SPEED_SKIP 25 39 | 40 | #ifdef MACHINE_EXPRESSION 41 | #define SIZE_WHEEL_IS_POTENTIOMETER 42 | #endif 43 | 44 | // enable or disable onboard flash chip debugging 45 | // press key F1 on the keybad to do a flash test 46 | #define DEBUG_FLASH 47 | //#define DEBUG_MODE //enables/disables wdtimer during debug mode 48 | 49 | #endif -------------------------------------------------------------------------------- /src/dial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dial.c 3 | * 4 | * Driver for 3 analog dials, connected as follows: 5 | * 6 | * dial | AVR 7 | *-------+----------- 8 | * size | PF0 (ADC0 ------------ On some machines this is a quadrature encoder, not a pot 9 | * speed | PF1 (ADC1) 10 | * press | PF2 (ADC2) 11 | * 12 | * Each input is a simple voltage divider between 0 and 5V, with 13 | * a few discrete settings where the pot clicks. 14 | * 15 | * This file is part of FreeExpression. 16 | * 17 | * https://github.com/thetazzbot/FreeExpression 18 | * 19 | * FreeExpression is free software: you can redistribute it and/or modify it 20 | * under the terms of the GNU General Public License version 2. 21 | * 22 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 23 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 24 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 25 | * License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 29 | * 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "keypad.h" 37 | #include "dial.h" 38 | #include "timer.h" 39 | #include "display.h" 40 | 41 | static uint8_t channel = 0; 42 | static unsigned char pvars[MAX_DIALS]; // holds previous values 43 | 44 | static unsigned char dial_adc[MAX_DIALS]; 45 | static unsigned char dial_steps[MAX_DIALS] = { 25, 5, 5 }; // weak association !! should use struct instead 46 | 47 | static int dial_setting( uint8_t dial ) 48 | { 49 | int step =(dial_adc[dial] * (dial_steps[dial]-1) + 125) / 250; 50 | 51 | return step+3; // +3 to have the dials set speed and pressure in the range of 3-7 -- middle of overall range 0-9 52 | } 53 | 54 | void dial_poll( void ) 55 | { 56 | unsigned char i; 57 | static unsigned char queued = 0; 58 | 59 | // records ADC readings from 2 or 3 ADC inputs on a round robin basis 60 | dial_adc[channel] = ADCH; 61 | 62 | if( ++channel == MAX_DIALS ) 63 | { 64 | channel = 0; 65 | queued = 1; 66 | } 67 | 68 | // setup for next measurement, 69 | ADMUX = (1 << ADLAR) | (1 << REFS0) | channel; // Change input channel 70 | ADCSRA |= (1 << ADSC); // start next conversion so it's ready to be read next time we come around 71 | 72 | if (! queued ) // wait until all ADC channels are read at least once before looking at the readings 73 | return; 74 | 75 | if(pvars[DIAL_SPEED] != (i=dial_setting( DIAL_SPEED))) 76 | { 77 | //sprintf(string,"Dial speed: %d\r",i); 78 | //display_puts( string ); 79 | //beep(); 80 | pvars[DIAL_SPEED]=i; 81 | timer_set_stepper_speed(i); 82 | keypadSet_Speed_state( ); // so that the +/- keys follow the speed settings 83 | 84 | } 85 | 86 | if(pvars[DIAL_PRESSURE] != (i=dial_setting( DIAL_PRESSURE ))) 87 | { 88 | //sprintf(string,"Dial pressure: %d\r",i); 89 | //display_puts( string ); 90 | //beep(); 91 | pvars[DIAL_PRESSURE]=i; 92 | timer_set_pen_pressure(i); 93 | keypadSet_Pressure_state( ); // so that the +/- keys follow the Pressure settings 94 | } 95 | 96 | #ifdef SIZE_WHEEL_IS_POTENTIOMETER 97 | if(pvars[DIAL_SIZE] != (i=dial_setting( DIAL_SIZE ))) 98 | { 99 | //sprintf(string,"Dial size: %d\r",i); 100 | //display_puts( string ); 101 | //beep(); 102 | pvars[DIAL_SIZE]=i; 103 | } 104 | #endif 105 | 106 | } 107 | 108 | void dial_init( void ) 109 | { 110 | /* 111 | REFS1 REFS0 Voltage Reference Selection(1) 112 | 0 0 AREF, Internal VREF turned off 113 | 0 1 AVCC with external capacitor at AREF pin 114 | */ 115 | // DIDR0 = 0x7; // disable digital input buffers on ADC0 to ADC2 --- mostly for current consumption though, potentiometers are low in impedance so it doesn't matter 116 | ADMUX = (1 << ADLAR) | ( 1 << REFS0| channel ) ; // 8 bit read mode, left justified result -- read only ADCH, using VCC for ADCref 117 | ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADPS2) | (1< 26 | #include 27 | 28 | extern FILE lcd; 29 | 30 | void lcd_init( void ); 31 | void lcd_position( unsigned char row, unsigned char col); // 0 based row 32 | int lcd_putchar( char c ,FILE *stream); 33 | void lcd_display_update(void); 34 | void lcd_puthex( uint8_t x ); 35 | 36 | #endif 37 | #endif MACHINE_CAKE -------------------------------------------------------------------------------- /src/display_oled.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The display is composed of an UG-2864ASYDT01 OLED module using an SSD1325 display driver chip. 3 | * The graphics library used is u8glib 4 | * 5 | * https://code.google.com/p/u8glib/ 6 | * 7 | * Device type can be either u8g_dev_ssd1325_nhd27oled_bw_sw_spi or the 2x variant, 8 | * u8g_dev_ssd1325_nhd27oled_2x_bw_sw_spi 9 | * 10 | * https://code.google.com/p/u8glib/wiki/device 11 | * 12 | * The UG-2864ASYDT01 module uses mainly four pins to interface with the AVR: 13 | * 14 | * SCK: PORTF, Bit 6 15 | * MOSI: PORTF, Bit 5 16 | * CS: PORTE, Bit 7 17 | * A0: PORTF, Bit 7 18 | * 19 | * On the motherboard of the Cricut Expression, the 10 pin header has the following 20 | * connections: 21 | * 22 | * Pin | Display | AVR 23 | *------+-------+--------- 24 | * 1 | GND | NC 25 | * 2 | Vcc | NC 26 | * 3 | D1/SDIN | PF5 27 | * 4 | D0/SCLK | PF6 28 | * 5 | DC# | PF7 29 | * 6 | NC | PE4 30 | * 7 | NC | PE5 31 | * 8 | RES | PE6 32 | * 9 | CS# | PE7 33 | * 10 | NC | 34 | * 35 | * This file is part of FreeExpression. 36 | * 37 | * https://github.com/thetazzbot/FreeExpression 38 | * 39 | * FreeExpression is free software: you can redistribute it and/or modify it 40 | * under the terms of the GNU General Public License version 2. 41 | * 42 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 43 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 44 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 45 | * License for more details. 46 | * 47 | * You should have received a copy of the GNU General Public License 48 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 49 | * 50 | */ 51 | 52 | /* 53 | TODO: Replace the u8glib, it is adding so much lag to the UI. I need to hand-craft 54 | a faster interface. 55 | */ 56 | #ifdef MACHINE_EXPRESSION 57 | #include 58 | #include 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include "./m2u8/u8g.h" 64 | #include "display_oled.h" 65 | #include "timer.h" 66 | 67 | 68 | void _oled_display_speed(void); 69 | void _oled_display_pressure(void); 70 | u8g_t u8g; 71 | static uint8_t cur_x=0,cur_y=0; 72 | char display_message[80]; // 4 lines of 20 chars?? 73 | 74 | // local functions 75 | /* 76 | Displays the currently selected speed as bars 77 | Must be called from inside the draw loop 78 | */ 79 | void _oled_display_speed(void) 80 | { 81 | int p=timer_get_stepper_speed(); 82 | // at least one bar will always show 83 | u8g_SetColorIndex(&u8g, 3); 84 | u8g_DrawBox(&u8g, 30,62,2,2); // 1 85 | if(p<2) u8g_SetColorIndex(&u8g, 1); 86 | u8g_DrawBox(&u8g, 33,61,2,3); // 2 87 | if(p<3) u8g_SetColorIndex(&u8g, 1); 88 | u8g_DrawBox(&u8g, 36,60,2,4); // 3 89 | if(p<4) u8g_SetColorIndex(&u8g, 1); 90 | u8g_DrawBox(&u8g, 39,59,2,5); // 4 91 | if(p<5) u8g_SetColorIndex(&u8g, 1); 92 | u8g_DrawBox(&u8g, 42,58,2,6); // 5 93 | u8g_SetColorIndex(&u8g, 3); 94 | } 95 | 96 | /* 97 | Displays the currently selected pressure as bars 98 | Must be called from inside the draw loop 99 | */ 100 | void _oled_display_pressure(void) 101 | { 102 | int p=timer_get_pen_pressure(); 103 | u8g_SetColorIndex(&u8g, 3); 104 | u8g_DrawBox(&u8g, 54,62,2,2); // 1 105 | if(p<2) u8g_SetColorIndex(&u8g, 1); 106 | u8g_DrawBox(&u8g, 57,61,2,3); // 2 107 | if(p<3) u8g_SetColorIndex(&u8g, 1); 108 | u8g_DrawBox(&u8g, 60,60,2,4); // 3 109 | if(p<4) u8g_SetColorIndex(&u8g, 1); 110 | u8g_DrawBox(&u8g, 63,59,2,5); // 4 111 | if(p<5) u8g_SetColorIndex(&u8g, 1); 112 | u8g_DrawBox(&u8g, 66,58,2,6); // 5 113 | u8g_SetColorIndex(&u8g, 3); 114 | } 115 | 116 | 117 | void oled_display_firstpage(void) 118 | { 119 | u8g_FirstPage(&u8g); 120 | } 121 | 122 | int oled_display_nextpage(void) 123 | { 124 | return u8g_NextPage(&u8g); 125 | } 126 | void oled_display_init(void) 127 | { 128 | /* select minimal prescaler (max system speed) */ 129 | CLKPR = 0xFF; 130 | // SCK MOSI CS D/C 131 | u8g_InitSPI(&u8g, &u8g_dev_ssd1325_nhd27oled_2x_gr_sw_spi, PN(5, 6), PN(5, 5), PN(4, 7),PN(5,7), PN(4,6)); 132 | u8g_SetRot180(&u8g); 133 | 134 | /* assign default color value */ 135 | u8g_SetColorIndex(&u8g, 3); /* max intensity */ 136 | // u8g_SetColorIndex(&u8g, 1); /* pixel on */ 137 | 138 | u8g_SetFont(&u8g, u8g_font_profont11); 139 | u8g_SetFontRefHeightExtendedText(&u8g); 140 | u8g_SetDefaultForegroundColor(&u8g); 141 | u8g_SetFontPosTop(&u8g); 142 | 143 | 144 | } 145 | 146 | // main screen redraw functions 147 | void oled_display_update(void) 148 | { 149 | oled_display_firstpage(); 150 | do { 151 | u8g_DrawStr(&u8g, cur_x, cur_y, display_message); 152 | _oled_display_speed(); 153 | _oled_display_pressure(); 154 | } while(oled_display_nextpage()); 155 | 156 | } 157 | 158 | /** 159 | * Displays a string using u8glib's "picture loop". There is 160 | * significant lag happening here. 161 | */ 162 | void oled_display_puts(const char *s) { 163 | strcpy(display_message,s); 164 | oled_display_update(); 165 | } 166 | 167 | 168 | 169 | /* 170 | * Horrible code that needs to go away and be replaced by something better 171 | */ 172 | 173 | void oled_display_println(char *s) { 174 | oled_display_puts(s); 175 | cur_y+=10; 176 | cur_x=0; 177 | } 178 | 179 | 180 | #endif //#ifdef MACHINE_EXPRESSION -------------------------------------------------------------------------------- /src/display_oled.h: -------------------------------------------------------------------------------- 1 | /* 2 | * display.h 3 | * 4 | * Created: 2/15/2015 12:03:50 PM 5 | * Author: Mark 6 | */ 7 | 8 | #ifdef MACHINE_EXPRESSION 9 | #ifndef DISPLAY_OLED_H_ 10 | #define DISPLAY_OLED_H_ 11 | 12 | void oled_display_init(void); 13 | void oled_display_firstpage(void); 14 | int oled_display_nextpage(void); 15 | void oled_display_puts(const char *s) ; 16 | void oled_display_println(char *s); 17 | void oled_display_update(void); 18 | #endif 19 | #endif //#ifdef MACHINE_EXPRESSION -------------------------------------------------------------------------------- /src/flash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * flash.c 3 | * 4 | * Driver for serial dataflash AT45DB041B on main board, attached as follows: 5 | * 6 | * This file is part of FreeExpression. 7 | * 8 | * https://github.com/thetazzbot/FreeExpression 9 | * 10 | * FreeExpression is free software: you can redistribute it and/or modify it 11 | * under the terms of the GNU General Public License version 2. 12 | * 13 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 14 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 16 | * License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 20 | * 21 | */ 22 | 23 | #ifndef FLASH_H 24 | #define FLASH_H 25 | 26 | 27 | #define SetBit(x,y) (x |= (y)) 28 | #define ClrBit(x,y) (x &=~(y)) 29 | #define ChkBit(x,y) (x & (y)) 30 | 31 | extern unsigned char PageBits; 32 | extern unsigned int PageSize; 33 | 34 | uint8_t flash_read_next_byte( void ); 35 | void flash_start_read(uint32_t offset); 36 | void flash_start_write(uint32_t offset); 37 | void flash_init( void ); 38 | uint8_t flash_write_next_byte(uint8_t data); 39 | void flash_test(void); 40 | void flash_flush(void); 41 | 42 | /*unsigned char Dataflash_Buffer_Read_Byte (unsigned char BufferNo, unsigned int IntPageAdr); 43 | void Dataflash_Buffer_Read_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr); 44 | void Dataflash_Buffer_Write_Enable (unsigned char BufferNo, unsigned int IntPageAdr); 45 | void Dataflash_Buffer_Write_Byte (unsigned char BufferNo, unsigned int IntPageAdr, unsigned char Data); 46 | void Dataflash_Buffer_Write_Str (unsigned char BufferNo, unsigned int IntPageAdr, unsigned int No_of_bytes, unsigned char *BufferPtr); 47 | void Dataflash_Buffer_To_Page (unsigned char BufferNo, unsigned int PageAdr); 48 | void Dataflash_Cont_Flash_Read_Enable (unsigned int PageAdr, unsigned int IntPageAdr); 49 | //#ifdef MTEXTRAS 50 | void Dataflash_Page_Erase (unsigned int PageAdr); // added by mthomas 51 | unsigned char Dataflash_Page_Buffer_Compare(unsigned char BufferNo, unsigned int PageAdr); // added by mthomas 52 | void Dataflash_Buffer_To_PageNE (unsigned char BufferNo, unsigned int PageAdr); 53 | 54 | unsigned char Dataflash_Dataflash_RW_SPI (unsigned char output); 55 | void Dataflash_DF_SPI_init (void); 56 | unsigned char Dataflash_Read_DF_status (void); 57 | void Dataflash_DF_CS_inactive(void); 58 | void Dataflash_DF_CS_active(void); 59 | */ 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/g_code.h: -------------------------------------------------------------------------------- 1 | #ifndef _GCODE_H 2 | #define _GCODE_H 3 | #include "shvars.h" 4 | 5 | /// Initialize the scanner. 6 | void gcode_init(void); 7 | 8 | /// Handle next character from the input. When action is determined, return one of the _hpgl_command values. 9 | /// Pass target coordinates in x and y. 10 | /// @param c input char 11 | /// @param x output: destination x (returns -1 if no data) 12 | /// @param y output: destination y (returns -1 if no data) 13 | /// @param lb output: next label character (see CMD_LB) 14 | /// @returns _hpgl_command 15 | int8_t gcode_char(char c, STEPPER_COORD* x, STEPPER_COORD* y); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/hackNotes.PDF: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/src/hackNotes.PDF -------------------------------------------------------------------------------- /src/hpgl.h: -------------------------------------------------------------------------------- 1 | #ifndef _HPGL_H 2 | #define _HPGL_H 3 | #include "shvars.h" 4 | /// HPGL commands. Returned by hpgl_char() when there is data and handled by do_stuff() in motori.c 5 | /// @see do_stuff() 6 | /// @see hpgl_char() 7 | enum _hpgl_command { 8 | CMD_ERR = -1, ///< Error 9 | CMD_CONT = 0, ///< Continue, do nothing (data coming) 10 | CMD_PA = 1, ///< Move to returned coordinates 11 | CMD_FS, ///< Pen pressure (nonstandard??) 12 | CMD_PD, ///< Pen down 13 | CMD_PU, ///< Pen up 14 | CMD_ARCABS, ///< Start arc absolute 15 | CMD_INIT, ///< Initialize 16 | CMD_SEEK0, ///< Locate home position 17 | CMD_LB0, ///< Mark label start 18 | CMD_LB, ///< Label text 19 | CMD_SI, ///< Absolute character size 20 | CMD_SR, ///< Relative character size 21 | CMD_DI, ///< Label direction: numpad[0]=sin(theta), numpad[1]=cos(theta) 22 | CMD_AS, ///< Acceleration Select: 0 = no acceleration (nonstandard) 23 | CMD_VS, ///< Velocity Select: 0 = fastest (nonstandard) 24 | }; 25 | 26 | /// Internal scanner state. 27 | /// @see hpgl_char() 28 | enum _scanner_state { 29 | STATE_EXP1 = 0, ///< Expect first char of a command 30 | STATE_EXP_F, 31 | STATE_EXP_P, 32 | STATE_EXP_S, 33 | STATE_EXP_I, 34 | STATE_EXP_A, 35 | STATE_EXP_L, 36 | STATE_EXP_D, 37 | STATE_EXP_V, 38 | 39 | STATE_X, 40 | STATE_Y, 41 | STATE_FS, ///< Set pressure 42 | STATE_SP, ///< Select pen 43 | STATE_SC, ///< Scale 44 | STATE_IP, ///< Coordinates 45 | STATE_LB, ///< Label text 46 | STATE_SI, ///< absolute character size in cm 47 | STATE_SR, ///< relative character size 48 | STATE_DT, ///< label terminator char 49 | STATE_DI, ///< label direction 50 | 51 | STATE_AS, ///< Acceleration Select (nonstandard: 0/1) 52 | STATE_VS, ///< Velocity Select (nonstandard: value = skip steps, the more the slower) 53 | 54 | STATE_EXP4, ///< Expect 4 numbers (like for AA, IP, SC) 55 | STATE_ARC, ///< Arc 56 | STATE_SKIP_END, ///< Skip all until semicolon 57 | }; 58 | 59 | /// Initialize the scanner. 60 | void hpgl_init(void); 61 | 62 | /// Handle next character from the input. When action is determined, return one of the _hpgl_command values. 63 | /// Pass target coordinates in x and y. 64 | /// @param c input char 65 | /// @param x output: destination x (returns -1 if no data) 66 | /// @param y output: destination y (returns -1 if no data) 67 | /// @param lb output: next label character (see CMD_LB) 68 | /// @returns _hpgl_command 69 | int8_t hpgl_char(char c, STEPPER_COORD* x, STEPPER_COORD* y, uint8_t* lb); 70 | 71 | 72 | #endif -------------------------------------------------------------------------------- /src/keypad.h: -------------------------------------------------------------------------------- 1 | /* 2 | * keypad.h 3 | * 4 | * Created: 3/23/2019 11:02:59 PM 5 | * Author: adeva 6 | */ 7 | 8 | #ifndef KEYPAD_H_ 9 | #define KEYPAD_H_ 10 | 11 | #ifdef MACHINE_CAKE 12 | #include "keypad_cake.h" 13 | #endif 14 | #ifdef MACHINE_EXPRESSION 15 | #include "keypad_expression.h" 16 | #endif 17 | 18 | int keypad_poll( void ); 19 | void keypad_init( void ); 20 | void keypad_set_leds( uint16_t mask ); 21 | char keypad_stop_pressed( void ); 22 | void keypadSet_Speed_state( void ); 23 | void keypadSet_Pressure_state( void ); 24 | int keypad_scan( void ); 25 | #define leds_on() do { PORTD &= ~(1 << 5); } while(0) // PD5 26 | #define leds_off() do { PORTD |= (1 << 5); } while(0) // PD5 27 | 28 | 29 | typedef enum _languge { 30 | HPGL=1, 31 | G_CODE, 32 | GPGL 33 | } en_language; 34 | 35 | extern en_language Lang; 36 | 37 | 38 | 39 | 40 | #endif /* KEYPAD_H_ */ -------------------------------------------------------------------------------- /src/keypad_cake.h: -------------------------------------------------------------------------------- 1 | /* keypad.h 2 | * 3 | This source original developped by https://github.com/Arlet/Freecut 4 | 5 | * This file is part of FreeExpression. 6 | * 7 | * https://github.com/thetazzbot/FreeExpression 8 | * 9 | * FreeExpression is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2. 11 | * 12 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 | * License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 19 | */ 20 | #ifdef MACHINE_CAKE 21 | #ifndef _KEYPAD_CAKE_H 22 | #define _KEYPAD_CAKE_H 23 | 24 | /* 25 | * These two defines indicate the X-Y size of the keyboard matrix and has to match the actual Hardware. 26 | * of the Expression and cake machine. 27 | * Do not change arbitrarily, but if your machine has a different size matrix make sure you learn the 28 | * key-codes that go together with a different size matrix first. 29 | */ 30 | 31 | #define KBD_MAX_COLS 20 32 | #define KBD_MAX_ROWS 5 33 | enum { 34 | 35 | KEYPAD_F1 =0, 36 | KEYPAD_F2, 37 | KEYPAD_1, 38 | KEYPAD_2, 39 | KEYPAD_3, 40 | KEYPAD_4, 41 | KEYPAD_5, 42 | KEYPAD_6, 43 | KEYPAD_7, 44 | KEYPAD_8, 45 | KEYPAD_9, 46 | KEYPAD_0, 47 | KEYPAD_SPACE, 48 | KEYPAD_BACKSPACE, 49 | KEYPAD_PORTRAIT, 50 | KEYPAD_FLIP, 51 | KEYPAD_MINUS, 52 | KEYPAD_OK, 53 | KEYPAD_PLUS, 54 | KEYPAD_XTRA1, 55 | KEYPAD_F3, 56 | KEYPAD_F4, 57 | KEYPAD_Q, 58 | KEYPAD_W, 59 | KEYPAD_E, 60 | KEYPAD_R, 61 | KEYPAD_T, 62 | KEYPAD_Y, 63 | KEYPAD_U, 64 | KEYPAD_I, 65 | KEYPAD_O, 66 | KEYPAD_P, 67 | KEYPAD_ClearDisplay, 68 | KEYPAD_RESETALL, 69 | KEYPAD_FITPAGE, 70 | KEYPAD_QUANTITY=35, 71 | // some missing buttons that are not on the machine 72 | KEYPAD_XTRA2=39, 73 | KEYPAD_F5, 74 | KEYPAD_F6, 75 | KEYPAD_A, 76 | KEYPAD_S, 77 | KEYPAD_D, 78 | KEYPAD_F, 79 | KEYPAD_G, 80 | KEYPAD_H, 81 | KEYPAD_J, 82 | KEYPAD_K, 83 | KEYPAD_L, 84 | KEYPAD_AMPERSAND, 85 | KEYPAD_REPEATLAST, 86 | KEYPAD_SOUNDONOFF, 87 | KEYPAD_MIXMATCH, 88 | KEYPAD_MULTICUT, 89 | KEYPAD_MOVEUPLEFT, 90 | KEYPAD_MOVEUP, 91 | KEYPAD_MOVEUPRIGHT, 92 | KEYPAD_LINERETURN, 93 | KEYPAD_MATERIALSAVER, 94 | KEYPAD_REALDIALSIZE, 95 | KEYPAD_Z, 96 | KEYPAD_X, 97 | KEYPAD_C, 98 | KEYPAD_V, 99 | KEYPAD_B, 100 | KEYPAD_N, 101 | KEYPAD_M, 102 | KEYPAD_COMMA, 103 | KEYPAD_PERIOD, 104 | KEYPAD_SLASH, 105 | KEYPAD_LOADLAST, 106 | KEYPAD_SETPAPERSIZE, 107 | KEYPAD_FITLENGTH, 108 | KEYPAD_CENTERPOINT, 109 | KEYPAD_MOVELEFT, 110 | KEYPAD_CUT, 111 | KEYPAD_MOVERIGHT, 112 | KEYPAD_SETTINGS, 113 | KEYPAD_SHIFT, 114 | KEYPAD_CUT_SHIFTLOCK, 115 | KEYPAD_EQUALS, 116 | KEYPAD_LEFTBRACKET, 117 | KEYPAD_RIGHTBRACKET, 118 | KEYPAD_LEFTBRACE, 119 | KEYPAD_RIGHTBRACE, 120 | KEYPAD_QUOTE, 121 | KEYPAD_49, 122 | KEYPAD_50=90, 123 | // Missing button 124 | KEYPAD_LOADMAT=92, 125 | KEYPAD_UNLOADMAT, 126 | KEYPAD_AUTOFILL, 127 | KEYPAD_MATSIZE, 128 | KEYPAD_MOVEDNLEFT, 129 | KEYPAD_MOVEDN , 130 | KEYPAD_MOVEDNRIGHT 131 | } KEYS; 132 | 133 | #endif 134 | #endif //#ifdef MACHINE_CAKE 135 | -------------------------------------------------------------------------------- /src/keypad_expression.h: -------------------------------------------------------------------------------- 1 | /* keypad.h 2 | * 3 | * This file is part of FreeExpression. 4 | * 5 | * https://github.com/thetazzbot/FreeExpression 6 | * 7 | * FreeExpression is free software: you can redistribute it and/or modify it 8 | * under the terms of the GNU General Public License version 2. 9 | * 10 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 13 | * License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 17 | */ 18 | #ifdef MACHINE_EXPRESSION 19 | #ifndef _KEYPAD_EXPRESSION_H 20 | #define _KEYPAD_EXPRESSION_H 21 | 22 | #define KBD_MAX_COLS 24 23 | #define KBD_MAX_ROWS 5 24 | enum { 25 | // KEYPAD_STOP, // not a scanned key, its a reset 26 | // I know it's kind of dumb to put numbers next to enums but if we decide to rename them or move them around, the number should stay with the name. 27 | KEYPAD_F1 = 0, 28 | KEYPAD_F2 = 1, 29 | KEYPAD_1 = 2, 30 | KEYPAD_2 = 3, 31 | KEYPAD_3 = 4, 32 | KEYPAD_4 = 5, 33 | KEYPAD_5 = 6, 34 | KEYPAD_6 = 7, 35 | KEYPAD_7 = 8, 36 | KEYPAD_8 = 9, 37 | KEYPAD_9 = 10, 38 | KEYPAD_0 = 11, 39 | KEYPAD_SPACE = 12, 40 | KEYPAD_BACKSPACE = 13, 41 | KEYPAD_PORTRAIT = 14, 42 | KEYPAD_FLIP = 15, 43 | KEYPAD_MINUS = 16, 44 | KEYPAD_OK = 17, 45 | KEYPAD_PLUS = 18, 46 | KEYPAD_XTRA1 = 19, 47 | KEYPAD_F3 = 24, 48 | KEYPAD_F4 = 25, 49 | KEYPAD_Q = 26, 50 | KEYPAD_W = 27, 51 | KEYPAD_E = 28, 52 | KEYPAD_R = 29, 53 | KEYPAD_T = 30, 54 | KEYPAD_Y = 31, 55 | KEYPAD_U = 32, 56 | KEYPAD_I = 33, 57 | KEYPAD_O = 34, 58 | KEYPAD_P = 35, 59 | KEYPAD_CHARDISPLAY = 36, 60 | KEYPAD_RESETALL = 37, 61 | KEYPAD_FITPAGE = 38, 62 | KEYPAD_QUANTITY = 39, 63 | KEYPAD_XTRA2 = 43, 64 | KEYPAD_F5 = 48, 65 | KEYPAD_F6 = 49, 66 | KEYPAD_A = 50, 67 | KEYPAD_S = 51, 68 | KEYPAD_D = 52, 69 | KEYPAD_F = 53, 70 | KEYPAD_G = 54, 71 | KEYPAD_H = 55, 72 | KEYPAD_J = 56, 73 | KEYPAD_K = 57, 74 | KEYPAD_L = 58, 75 | KEYPAD_SEMICOLON = 59, 76 | KEYPAD_REPEATLAST = 60, 77 | KEYPAD_SOUNDONOFF = 61, 78 | KEYPAD_MIXMATCH = 62, 79 | KEYPAD_MULTICUT = 63, 80 | KEYPAD_MOVEUPLEFT = 64, 81 | KEYPAD_MOVEUP = 65, 82 | KEYPAD_MOVEUPRIGHT = 66, 83 | KEYPAD_LINERETURN = 67, 84 | KEYPAD_MATERIALSAVER = 72, 85 | KEYPAD_REALDIALSIZE = 73, 86 | KEYPAD_Z = 74, 87 | KEYPAD_X = 75, 88 | KEYPAD_C = 76, 89 | KEYPAD_V = 77, 90 | KEYPAD_B = 78, 91 | KEYPAD_N = 79, 92 | KEYPAD_M = 80, 93 | KEYPAD_COMMA = 81, 94 | KEYPAD_PERIOD = 82, 95 | KEYPAD_SLASH = 83, 96 | KEYPAD_LOADLAST = 84, 97 | KEYPAD_SETCUTAREA = 85, 98 | KEYPAD_FITLENGTH = 86, 99 | KEYPAD_CENTERPOINT = 87, 100 | KEYPAD_MOVELEFT = 88, 101 | KEYPAD_CUT = 89, 102 | KEYPAD_MOVERIGHT = 90, 103 | KEYPAD_SETTINGS = 91, 104 | KEYPAD_SHIFT = 96, 105 | KEYPAD_CUT_SHIFTLOCK = 97, 106 | KEYPAD_EQUALS = 100, 107 | KEYPAD_LEFTBRACKET = 101, 108 | KEYPAD_RIGHTBRACKET = 102, 109 | KEYPAD_LEFTBRACE = 103, 110 | KEYPAD_RIGHTBRACE = 104, 111 | KEYPAD_QUOTE = 105, 112 | KEYPAD_49 = 106, 113 | KEYPAD_50 = 107, 114 | KEYPAD_LOADMAT=108, 115 | KEYPAD_UNLOADMAT=109, 116 | KEYPAD_AUTOFILL = 110, 117 | KEYPAD_MATSIZE = 111, 118 | KEYPAD_MOVEDNLEFT = 112, 119 | KEYPAD_MOVEDN = 113, 120 | KEYPAD_MOVEDNRIGHT = 114 121 | } KEYS; 122 | 123 | #endif 124 | #endif //#ifdef MACHINE_EXPRESSION -------------------------------------------------------------------------------- /src/m2u8/Debug/makedep.mk: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Automatically-generated file. Do not edit or delete the file 3 | ################################################################################ 4 | 5 | u8g_bitmap.c 6 | 7 | u8g_circle.c 8 | 9 | u8g_clip.c 10 | 11 | u8g_com_api.c 12 | 13 | u8g_com_api_16gr.c 14 | 15 | u8g_com_atmega_sw_spi.c 16 | 17 | u8g_com_i2c.c 18 | 19 | u8g_com_io.c 20 | 21 | u8g_com_null.c 22 | 23 | u8g_cursor.c 24 | 25 | u8g_delay.c 26 | 27 | u8g_dev_null.c 28 | 29 | u8g_dev_ssd1325_nhd27oled_bw_new.c 30 | 31 | u8g_dev_ssd1325_nhd27oled_gr_new.c 32 | 33 | u8g_ellipse.c 34 | 35 | u8g_font.c 36 | 37 | u8g_font_data.c 38 | 39 | u8g_line.c 40 | 41 | u8g_ll_api.c 42 | 43 | u8g_page.c 44 | 45 | u8g_pb.c 46 | 47 | u8g_pb14v1.c 48 | 49 | u8g_pb16h1.c 50 | 51 | u8g_pb16h2.c 52 | 53 | u8g_pb16v1.c 54 | 55 | u8g_pb16v2.c 56 | 57 | u8g_pb32h1.c 58 | 59 | u8g_pb8h1.c 60 | 61 | u8g_pb8h1f.c 62 | 63 | u8g_pb8h2.c 64 | 65 | u8g_pb8h8.c 66 | 67 | u8g_pb8v1.c 68 | 69 | u8g_pb8v2.c 70 | 71 | u8g_pbxh16.c 72 | 73 | u8g_pbxh24.c 74 | 75 | u8g_polygon.c 76 | 77 | u8g_rect.c 78 | 79 | u8g_rot.c 80 | 81 | u8g_scale.c 82 | 83 | u8g_state.c 84 | 85 | u8g_u16toa.c 86 | 87 | u8g_u8toa.c 88 | 89 | u8g_virtual_screen.c 90 | 91 | -------------------------------------------------------------------------------- /src/m2u8/m2u8.componentinfo.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Device 8 | Startup 9 | 10 | 11 | Atmel 12 | 1.2.0 13 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs 14 | 15 | 16 | 17 | 18 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include 19 | 20 | include 21 | C 22 | 23 | 24 | include 25 | 26 | 27 | 28 | 29 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\include\avr\iom1281.h 30 | 31 | header 32 | C 33 | gp4852szaErIVeiiC0MhRg== 34 | 35 | include/avr/iom1281.h 36 | 37 | 38 | 39 | 40 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\library.c 41 | template 42 | source 43 | C Lib 44 | 2/NZD/YM3hWVTzqme3bDXw== 45 | 46 | templates/library.c 47 | Main file (.c) 48 | 49 | 50 | 51 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\templates\library.cpp 52 | template 53 | source 54 | C Lib 55 | Ztu2zWWQnYWBswuEN+3iHQ== 56 | 57 | templates/library.cpp 58 | Main file (.cpp) 59 | 60 | 61 | 62 | C:/Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.209\gcc\dev\atmega1281 63 | 64 | libraryPrefix 65 | GCC 66 | 67 | 68 | gcc/dev/atmega1281 69 | 70 | 71 | 72 | 73 | ATmega_DFP 74 | C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.209/Atmel.ATmega_DFP.pdsc 75 | 1.2.209 76 | true 77 | ATmega1281 78 | 79 | 80 | 81 | Resolved 82 | Fixed 83 | true 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/m2u8/u8g_bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_bitmap.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap) 40 | { 41 | while( cnt > 0 ) 42 | { 43 | u8g_Draw8Pixel(u8g, x, y, 0, *bitmap); 44 | bitmap++; 45 | cnt--; 46 | x+=8; 47 | } 48 | } 49 | 50 | void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap) 51 | { 52 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 53 | return; 54 | while( h > 0 ) 55 | { 56 | u8g_DrawHBitmap(u8g, x, y, cnt, bitmap); 57 | bitmap += cnt; 58 | y++; 59 | h--; 60 | } 61 | } 62 | 63 | 64 | void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap) 65 | { 66 | while( cnt > 0 ) 67 | { 68 | u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap)); 69 | bitmap++; 70 | cnt--; 71 | x+=8; 72 | } 73 | } 74 | 75 | void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 76 | { 77 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 78 | return; 79 | while( h > 0 ) 80 | { 81 | u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap); 82 | bitmap += cnt; 83 | y++; 84 | h--; 85 | } 86 | } 87 | 88 | /*=========================================================================*/ 89 | 90 | static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap) 91 | { 92 | uint8_t d; 93 | x+=7; 94 | while( w >= 8 ) 95 | { 96 | u8g_Draw8Pixel(u8g, x, y, 2, *bitmap); 97 | bitmap++; 98 | w-= 8; 99 | x+=8; 100 | } 101 | if ( w > 0 ) 102 | { 103 | d = *bitmap; 104 | x -= 7; 105 | do 106 | { 107 | if ( d & 1 ) 108 | u8g_DrawPixel(u8g, x, y); 109 | x++; 110 | w--; 111 | d >>= 1; 112 | } while ( w > 0 ); 113 | } 114 | } 115 | 116 | void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap) 117 | { 118 | u8g_uint_t b; 119 | b = w; 120 | b += 7; 121 | b >>= 3; 122 | 123 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 124 | return; 125 | 126 | while( h > 0 ) 127 | { 128 | u8g_DrawHXBM(u8g, x, y, w, bitmap); 129 | bitmap += b; 130 | y++; 131 | h--; 132 | } 133 | } 134 | 135 | static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap) 136 | { 137 | uint8_t d; 138 | x+=7; 139 | while( w >= 8 ) 140 | { 141 | u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap)); 142 | bitmap++; 143 | w-= 8; 144 | x+=8; 145 | } 146 | if ( w > 0 ) 147 | { 148 | d = u8g_pgm_read(bitmap); 149 | x -= 7; 150 | do 151 | { 152 | if ( d & 1 ) 153 | u8g_DrawPixel(u8g, x, y); 154 | x++; 155 | w--; 156 | d >>= 1; 157 | } while ( w > 0 ); 158 | } 159 | } 160 | 161 | void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 162 | { 163 | u8g_uint_t b; 164 | b = w; 165 | b += 7; 166 | b >>= 3; 167 | 168 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 169 | return; 170 | while( h > 0 ) 171 | { 172 | u8g_DrawHXBMP(u8g, x, y, w, bitmap); 173 | bitmap += b; 174 | y++; 175 | h--; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/m2u8/u8g_clip.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_clip.c 4 | 5 | procedures for clipping 6 | taken over from procs in u8g_pb.c 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | Notes 38 | 39 | This is one of the most critical parts of u8glib. It must be fast, but still reliable. 40 | Based on the intersection program (see tools folder), there is minimized version of 41 | the condition for the intersaction test: 42 | minimized version 43 | ---1----0 1 b1 <= a2 && b1 > b2 44 | -----1--0 1 b2 >= a1 && b1 > b2 45 | ---1-1--- 1 b1 <= a2 && b2 >= a1 46 | It includes the assumption, that a1 <= a2 is always true (correct, because 47 | a1, a2 are the page dimensions. 48 | 49 | The direct implementation of the above result is done in: 50 | uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 51 | However, this is slower than a decision tree version: 52 | static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 53 | Also suprising is, that the macro implementation is slower than the inlined version. 54 | 55 | The decision tree is based on the expansion of the truth table. 56 | 57 | */ 58 | 59 | #include "u8g.h" 60 | 61 | #ifdef __GNUC__ 62 | #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline)) 63 | #else 64 | #define U8G_ALWAYS_INLINE 65 | #endif 66 | 67 | /* 68 | intersection assumptions: 69 | a1 <= a2 is always true 70 | 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | 77 | #ifdef OLD_CODE_WHICH_IS_TOO_SLOW 78 | static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 79 | { 80 | uint8_t c1, c2, c3, tmp; 81 | c1 = v0 <= a1; 82 | c2 = v1 >= a0; 83 | c3 = v0 > v1; 84 | 85 | tmp = c1; 86 | c1 &= c2; 87 | c2 &= c3; 88 | c3 &= tmp; 89 | c1 |= c2; 90 | c1 |= c3; 91 | return c1 & 1; 92 | } 93 | #endif 94 | 95 | #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) )) 96 | 97 | //static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE; 98 | static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 99 | { 100 | /* surprisingly the macro leads to larger code */ 101 | /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */ 102 | if ( v0 <= a1 ) 103 | { 104 | if ( v1 >= a0 ) 105 | { 106 | return 1; 107 | } 108 | else 109 | { 110 | if ( v0 > v1 ) 111 | { 112 | return 1; 113 | } 114 | else 115 | { 116 | return 0; 117 | } 118 | } 119 | } 120 | else 121 | { 122 | if ( v1 >= a0 ) 123 | { 124 | if ( v0 > v1 ) 125 | { 126 | return 1; 127 | } 128 | else 129 | { 130 | return 0; 131 | } 132 | } 133 | else 134 | { 135 | return 0; 136 | } 137 | } 138 | } 139 | 140 | 141 | uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) 142 | { 143 | register u8g_uint_t tmp; 144 | tmp = y; 145 | tmp += h; 146 | tmp--; 147 | if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 ) 148 | return 0; 149 | 150 | tmp = x; 151 | tmp += w; 152 | tmp--; 153 | return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp); 154 | } 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time) 40 | { 41 | return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL); 42 | } 43 | 44 | void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev) 45 | { 46 | dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL); 47 | } 48 | 49 | /* cs contains the chip number, which should be enabled */ 50 | void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs) 51 | { 52 | dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL); 53 | } 54 | 55 | void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev) 56 | { 57 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL); 58 | } 59 | 60 | void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev) 61 | { 62 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL); 63 | } 64 | 65 | 66 | void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address) 67 | { 68 | dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL); 69 | } 70 | 71 | uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val) 72 | { 73 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL); 74 | } 75 | 76 | uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq) 77 | { 78 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq); 79 | } 80 | 81 | uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq) 82 | { 83 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq); 84 | } 85 | 86 | /* 87 | sequence := { direct_value | escape_sequence } 88 | direct_value := 0..254 89 | escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 90 | value_255 := 255 255 91 | sequence_end = 255 254 92 | delay := 255 0..127 93 | adr := 255 0x0e0 .. 0x0ef 94 | cs := 255 0x0d0 .. 0x0df 95 | not_used := 255 101..254 96 | 97 | #define U8G_ESC_DLY(x) 255, ((x) & 0x7f) 98 | #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) 99 | #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) 100 | #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) 101 | #define U8G_ESC_END 255, 254 102 | #define U8G_ESC_255 255, 255 103 | #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) 104 | 105 | */ 106 | uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) 107 | { 108 | uint8_t is_escape = 0; 109 | uint8_t value; 110 | for(;;) 111 | { 112 | value = u8g_pgm_read(esc_seq); 113 | if ( is_escape == 0 ) 114 | { 115 | if ( value != 255 ) 116 | { 117 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 118 | return 0; 119 | } 120 | else 121 | { 122 | is_escape = 1; 123 | } 124 | } 125 | else 126 | { 127 | if ( value == 255 ) 128 | { 129 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 130 | return 0; 131 | } 132 | else if ( value == 254 ) 133 | { 134 | break; 135 | } 136 | else if ( value >= 0x0f0 ) 137 | { 138 | /* not yet used, do nothing */ 139 | } 140 | else if ( value >= 0xe0 ) 141 | { 142 | u8g_SetAddress(u8g, dev, value & 0x0f); 143 | } 144 | else if ( value >= 0xd0 ) 145 | { 146 | u8g_SetChipSelect(u8g, dev, value & 0x0f); 147 | } 148 | else if ( value >= 0xc0 ) 149 | { 150 | u8g_SetResetLow(u8g, dev); 151 | value &= 0x0f; 152 | value <<= 4; 153 | value+=2; 154 | u8g_Delay(value); 155 | u8g_SetResetHigh(u8g, dev); 156 | u8g_Delay(value); 157 | } 158 | else if ( value >= 0xbe ) 159 | { 160 | /* not yet implemented */ 161 | /* u8g_SetVCC(u8g, dev, value & 0x01); */ 162 | } 163 | else if ( value <= 127 ) 164 | { 165 | u8g_Delay(value); 166 | } 167 | is_escape = 0; 168 | } 169 | esc_seq++; 170 | } 171 | return 1; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_api_16gr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api_16gr.c 4 | 5 | Extension of the com api for devices with 16 graylevels (4 bit per pixel). 6 | This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 7 | mainly intended for SSD OLEDs 8 | 9 | Universal 8bit Graphics Library 10 | 11 | Copyright (c) 2011, olikraus@gmail.com 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this list 18 | of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or other 22 | materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 26 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 36 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */ 44 | /* topbit (msb) is sent last */ 45 | /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */ 46 | uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 47 | { 48 | static uint8_t buf[4]; 49 | static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff }; 50 | buf [3] = map[b & 3]; 51 | b>>=2; 52 | buf [2] = map[b & 3]; 53 | b>>=2; 54 | buf [1] = map[b & 3]; 55 | b>>=2; 56 | buf [0] = map[b & 3]; 57 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf); 58 | } 59 | 60 | uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 61 | { 62 | do 63 | { 64 | if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 ) 65 | return 0; 66 | cnt--; 67 | } while( cnt != 0 ); 68 | return 1; 69 | } 70 | 71 | /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */ 72 | uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 73 | { 74 | //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc}; 75 | //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff}; 76 | static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff}; 77 | uint8_t bb; 78 | bb = b; 79 | bb &= 15; 80 | b>>=4; 81 | dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL); 82 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL); 83 | } 84 | 85 | uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 86 | { 87 | do 88 | { 89 | if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 ) 90 | return 0; 91 | cnt--; 92 | } while( cnt != 0 ); 93 | return 1; 94 | } 95 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_arduino_attiny85_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_ATtiny85_std_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | // Uses code from tinySPI Written by Nick Gammon 37 | // March 2013 38 | 39 | // ATMEL ATTINY45 / ARDUINO pin mappings 40 | // 41 | // +-\/-+ 42 | // RESET Ain0 (D 5) PB5 1| |8 Vcc 43 | // CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL 44 | // CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO 45 | // GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA 46 | // +----+ 47 | 48 | 49 | #include "u8g.h" 50 | 51 | 52 | #if defined(ARDUINO) && defined(__AVR_ATtiny85__) 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | const byte DI = 0; // D0, pin 5 Data In 61 | const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI) 62 | const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock 63 | 64 | uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val) 65 | { 66 | USIDR = val; // byte to output 67 | USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero 68 | do 69 | { 70 | USICR = _BV (USIWM0) // 3-wire mode 71 | | _BV (USICS1) | _BV (USICLK) // Software clock strobe 72 | | _BV (USITC); // Toggle Clock Port Pin 73 | } 74 | while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set 75 | 76 | return USIDR; // return read data 77 | } 78 | 79 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 80 | { 81 | switch(msg) 82 | { 83 | case U8G_COM_MSG_INIT: 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed 85 | pinMode (USCK, OUTPUT); 86 | pinMode (DO, OUTPUT); 87 | pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT); 88 | pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT); 89 | USICR = _BV (USIWM0); // 3-wire mode 90 | u8g_MicroDelay(); 91 | break; 92 | 93 | case U8G_COM_MSG_STOP: 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 98 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 99 | break; 100 | 101 | case U8G_COM_MSG_CHIP_SELECT: 102 | if ( arg_val == 0 ) 103 | { 104 | /* disable */ 105 | u8g_MicroDelay(); 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 107 | u8g_MicroDelay(); 108 | } 109 | else 110 | { 111 | /* enable */ 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 113 | u8g_MicroDelay(); 114 | } 115 | break; 116 | 117 | case U8G_COM_MSG_WRITE_BYTE: 118 | u8g_arduino_ATtiny85_spi_out(arg_val); 119 | u8g_MicroDelay(); 120 | break; 121 | 122 | case U8G_COM_MSG_WRITE_SEQ: 123 | { 124 | register uint8_t *ptr = arg_ptr; 125 | while( arg_val > 0 ) 126 | { 127 | u8g_arduino_ATtiny85_spi_out(*ptr++); 128 | arg_val--; 129 | } 130 | } 131 | break; 132 | 133 | case U8G_COM_MSG_WRITE_SEQ_P: 134 | { 135 | register uint8_t *ptr = arg_ptr; 136 | while( arg_val > 0 ) 137 | { 138 | u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr)); 139 | ptr++; 140 | arg_val--; 141 | } 142 | } 143 | break; 144 | 145 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 146 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 147 | u8g_MicroDelay(); 148 | break; 149 | } 150 | return 1; 151 | } 152 | 153 | #else /* ARDUINO */ 154 | 155 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 156 | { 157 | return 1; 158 | } 159 | 160 | #endif /* ARDUINO */ -------------------------------------------------------------------------------- /src/m2u8/u8g_com_arduino_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_common.c 4 | 5 | shared procedures for the arduino communication procedures 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #if defined(ARDUINO) 42 | 43 | #if ARDUINO < 100 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value) 50 | { 51 | uint8_t pin; 52 | pin = u8g->pin_list[pin_index]; 53 | if ( pin != U8G_PIN_NONE ) 54 | digitalWrite(pin, value); 55 | } 56 | 57 | /* this procedure does not set the RW pin */ 58 | void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g) 59 | { 60 | uint8_t i; 61 | /* skip the RW pin, which is the last pin in the list */ 62 | for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ ) 63 | { 64 | if ( u8g->pin_list[i] != U8G_PIN_NONE ) 65 | { 66 | pinMode(u8g->pin_list[i], OUTPUT); 67 | digitalWrite(u8g->pin_list[i], HIGH); 68 | } 69 | } 70 | } 71 | 72 | 73 | #endif 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_arduino_hw_usart_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_hw_usart_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | SPI Clock Cycle Type 35 | 36 | SSD1351 50ns 20 MHz 37 | SSD1322 300ns 3.3 MHz 38 | SSD1327 300ns 39 | SSD1306 300ns 40 | ST7565 400ns 2.5 MHz 41 | ST7920 400ns 42 | 43 | */ 44 | 45 | #include "u8g.h" 46 | 47 | #if defined(ARDUINO) 48 | 49 | #if defined(__AVR_ATmega32U4__ ) 50 | 51 | #include 52 | #include 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | 61 | 62 | static uint8_t u8g_usart_spi_out(uint8_t data) 63 | { 64 | /* send data */ 65 | UDR1 = data; 66 | /* wait for empty transmit buffer */ 67 | while(!(UCSR1A & (1 << UDRE1))); 68 | 69 | return UDR1; 70 | } 71 | 72 | 73 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 74 | { 75 | switch(msg) 76 | { 77 | case U8G_COM_MSG_STOP: 78 | break; 79 | 80 | case U8G_COM_MSG_INIT: 81 | /* SCK is already an output as we overwrite TXLED */ 82 | u8g_com_arduino_assign_pin_output_high(u8g); 83 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 84 | 85 | // Init interface at 2MHz 86 | UBRR1 = 0x00; 87 | UCSR1C = (1 << UMSEL11) | (1 << UMSEL10); 88 | UCSR1B = (1 << TXEN1); 89 | UBRR1 = 3; 90 | 91 | break; 92 | 93 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 94 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 95 | break; 96 | 97 | case U8G_COM_MSG_CHIP_SELECT: 98 | if ( arg_val == 0 ) 99 | { 100 | /* disable */ 101 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 102 | } 103 | else 104 | { 105 | /* enable */ 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 107 | } 108 | break; 109 | 110 | case U8G_COM_MSG_RESET: 111 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 113 | break; 114 | 115 | case U8G_COM_MSG_WRITE_BYTE: 116 | u8g_usart_spi_out(arg_val); 117 | break; 118 | 119 | case U8G_COM_MSG_WRITE_SEQ: 120 | { 121 | register uint8_t *ptr = arg_ptr; 122 | while( arg_val > 0 ) 123 | { 124 | u8g_usart_spi_out(*ptr++); 125 | arg_val--; 126 | } 127 | } 128 | break; 129 | case U8G_COM_MSG_WRITE_SEQ_P: 130 | { 131 | register uint8_t *ptr = arg_ptr; 132 | while( arg_val > 0 ) 133 | { 134 | u8g_usart_spi_out(u8g_pgm_read(ptr)); 135 | ptr++; 136 | arg_val--; 137 | } 138 | } 139 | break; 140 | } 141 | return 1; 142 | } 143 | 144 | /* #elif defined(__18CXX) || defined(__PIC32MX) */ 145 | /* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */ 146 | 147 | #else /* __AVR_ATmega32U4__ */ 148 | 149 | #endif /* __AVR_ATmega32U4__ */ 150 | 151 | #else /* ARDUINO */ 152 | 153 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 154 | { 155 | return 1; 156 | } 157 | 158 | #endif /* ARDUINO */ 159 | 160 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_arduino_std_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_std_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #include "u8g.h" 37 | 38 | 39 | #if defined(ARDUINO) 40 | 41 | #if ARDUINO < 100 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | void u8g_arduino_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) 48 | { 49 | uint8_t i = 8; 50 | do 51 | { 52 | if ( val & 128 ) 53 | digitalWrite(dataPin, HIGH); 54 | else 55 | digitalWrite(dataPin, LOW); 56 | val <<= 1; 57 | u8g_MicroDelay(); /* 23 Sep 2012 */ 58 | //delay(1); 59 | digitalWrite(clockPin, HIGH); 60 | u8g_MicroDelay(); /* 23 Sep 2012 */ 61 | //delay(1); 62 | digitalWrite(clockPin, LOW); 63 | u8g_MicroDelay(); /* 23 Sep 2012 */ 64 | //delay(1); 65 | i--; 66 | } while( i != 0 ); 67 | } 68 | 69 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 70 | { 71 | switch(msg) 72 | { 73 | case U8G_COM_MSG_INIT: 74 | u8g_com_arduino_assign_pin_output_high(u8g); 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 76 | u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW); 77 | break; 78 | 79 | case U8G_COM_MSG_STOP: 80 | break; 81 | 82 | case U8G_COM_MSG_RESET: 83 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 85 | break; 86 | 87 | case U8G_COM_MSG_CHIP_SELECT: 88 | if ( arg_val == 0 ) 89 | { 90 | /* disable */ 91 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 92 | } 93 | else 94 | { 95 | /* enable */ 96 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 97 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 98 | } 99 | break; 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | 128 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 130 | break; 131 | } 132 | return 1; 133 | } 134 | 135 | #else /* ARDUINO */ 136 | 137 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 138 | { 139 | return 1; 140 | } 141 | 142 | #endif /* ARDUINO */ 143 | 144 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_atmega_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | 53 | #if defined(__AVR__) 54 | #define U8G_ATMEGA_HW_SPI 55 | 56 | /* remove the definition for attiny */ 57 | #if __AVR_ARCH__ == 2 58 | #undef U8G_ATMEGA_HW_SPI 59 | #endif 60 | #if __AVR_ARCH__ == 25 61 | #undef U8G_ATMEGA_HW_SPI 62 | #endif 63 | #endif 64 | 65 | 66 | #if defined(U8G_ATMEGA_HW_SPI) 67 | 68 | #include 69 | #include 70 | 71 | 72 | static uint8_t u8g_atmega_spi_out(uint8_t data) 73 | { 74 | /* unsigned char x = 100; */ 75 | /* send data */ 76 | SPDR = data; 77 | /* wait for transmission */ 78 | while (!(SPSR & (1< 0 ) 158 | { 159 | u8g_atmega_spi_out(*ptr++); 160 | arg_val--; 161 | } 162 | } 163 | break; 164 | case U8G_COM_MSG_WRITE_SEQ_P: 165 | { 166 | register uint8_t *ptr = arg_ptr; 167 | while( arg_val > 0 ) 168 | { 169 | u8g_atmega_spi_out(u8g_pgm_read(ptr)); 170 | ptr++; 171 | arg_val--; 172 | } 173 | } 174 | break; 175 | } 176 | return 1; 177 | } 178 | 179 | #else 180 | 181 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 182 | { 183 | return 1; 184 | } 185 | 186 | #endif 187 | 188 | 189 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_atmega_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | #if defined(__AVR__) 40 | 41 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 42 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 43 | { 44 | uint8_t i = 8; 45 | do 46 | { 47 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 48 | val <<= 1; 49 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 50 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 51 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 52 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 53 | i--; 54 | } while( i != 0 ); 55 | } 56 | 57 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 58 | { 59 | switch(msg) 60 | { 61 | case U8G_COM_MSG_INIT: 62 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 63 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 64 | u8g_SetPIOutput(u8g, U8G_PI_A0); 65 | u8g_SetPIOutput(u8g, U8G_PI_CS); 66 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 67 | 68 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 69 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 70 | u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 71 | u8g_SetPILevel(u8g, U8G_PI_A0, 0); 72 | break; 73 | 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 78 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 79 | break; 80 | 81 | case U8G_COM_MSG_CHIP_SELECT: 82 | 83 | if ( arg_val == 0 ) 84 | { 85 | /* disable */ 86 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 87 | } 88 | else 89 | { 90 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 91 | /* enable */ 92 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 93 | } 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_atmega_sw_spi_shift_out(u8g, arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | } 128 | return 1; 129 | } 130 | 131 | #else 132 | 133 | 134 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 135 | { 136 | return 1; 137 | } 138 | 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_null.c 4 | 5 | communication null device 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 42 | { 43 | switch(msg) 44 | { 45 | case U8G_COM_MSG_INIT: 46 | break; 47 | case U8G_COM_MSG_STOP: 48 | break; 49 | 50 | 51 | case U8G_COM_MSG_CHIP_SELECT: 52 | /* arg_val contains the chip number, which should be enabled */ 53 | break; 54 | 55 | 56 | case U8G_COM_MSG_WRITE_BYTE: 57 | break; 58 | case U8G_COM_MSG_WRITE_SEQ: 59 | break; 60 | } 61 | return 1; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_raspberrypi_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_raspberrypi_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | 53 | 54 | #if defined(U8G_RASPBERRY_PI) 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 63 | { 64 | switch(msg) 65 | { 66 | case U8G_COM_MSG_STOP: 67 | break; 68 | 69 | case U8G_COM_MSG_INIT: 70 | // check wiringPi setup 71 | if (wiringPiSetup() == -1) 72 | { 73 | printf("wiringPi-Error\n"); 74 | exit(1); 75 | } 76 | 77 | if (wiringPiSPISetup (0, 100000) < 0) 78 | { 79 | printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ; 80 | exit (1) ; 81 | } 82 | 83 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 84 | u8g_SetPIOutput(u8g, U8G_PI_A0); 85 | 86 | break; 87 | 88 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 89 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 90 | break; 91 | 92 | case U8G_COM_MSG_CHIP_SELECT: 93 | /* Done by the SPI hardware */ 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | case U8G_COM_MSG_WRITE_BYTE: 101 | wiringPiSPIDataRW (0, &arg_val, 1) ; 102 | break; 103 | 104 | case U8G_COM_MSG_WRITE_SEQ: 105 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 106 | break; 107 | 108 | case U8G_COM_MSG_WRITE_SEQ_P: 109 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 110 | break; 111 | } 112 | return 1; 113 | } 114 | 115 | #else 116 | 117 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 118 | { 119 | return 1; 120 | } 121 | 122 | #endif 123 | 124 | 125 | -------------------------------------------------------------------------------- /src/m2u8/u8g_com_raspberrypi_ssd_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | Special pin usage: 3 | U8G_PI_I2C_OPTION additional options 4 | U8G_PI_A0_STATE used to store the last value of the command/data register selection 5 | U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device 6 | U8G_PI_SCL clock line (NOT USED) 7 | U8G_PI_SDA data line (NOT USED) 8 | 9 | U8G_PI_RESET reset line (currently disabled, see below) 10 | 11 | Protocol: 12 | SLA, Cmd/Data Selection, Arguments 13 | The command/data register is selected by a special instruction byte, which is sent after SLA 14 | 15 | The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode 16 | */ 17 | 18 | #include "u8g.h" 19 | 20 | #if defined(U8G_RASPBERRY_PI) 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define I2C_SLA 0x3c 29 | #define I2C_CMD_MODE 0x000 30 | #define I2C_DATA_MODE 0x040 31 | 32 | #if defined(U8G_WITH_PINLIST) 33 | 34 | uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g) 35 | { 36 | /* are we requested to set the a0 state? */ 37 | if ( u8g->pin_list[U8G_PI_SET_A0] == 0 ) 38 | return 1; 39 | 40 | /* setup bus, might be a repeated start */ 41 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 42 | return 0; 43 | if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 ) 44 | { 45 | if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 ) 46 | return 0; 47 | } 48 | else 49 | { 50 | if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 ) 51 | return 0; 52 | } 53 | 54 | 55 | u8g->pin_list[U8G_PI_SET_A0] = 0; 56 | return 1; 57 | } 58 | 59 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 60 | { 61 | switch(msg) 62 | { 63 | case U8G_COM_MSG_INIT: 64 | u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]); 65 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 66 | u8g_SetPIOutput(u8g, U8G_PI_A0); 67 | break; 68 | 69 | case U8G_COM_MSG_STOP: 70 | break; 71 | 72 | case U8G_COM_MSG_RESET: 73 | break; 74 | 75 | case U8G_COM_MSG_CHIP_SELECT: 76 | u8g->pin_list[U8G_PI_A0_STATE] = 0; 77 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */ 78 | if ( arg_val == 0 ) 79 | { 80 | /* disable chip, send stop condition */ 81 | u8g_i2c_stop(); 82 | } 83 | else 84 | { 85 | /* enable, do nothing: any byte writing will trigger the i2c start */ 86 | } 87 | break; 88 | 89 | case U8G_COM_MSG_WRITE_BYTE: 90 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 91 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 92 | return u8g_i2c_stop(), 0; 93 | if ( u8g_i2c_send_byte(arg_val) == 0 ) 94 | return u8g_i2c_stop(), 0; 95 | // u8g_i2c_stop(); 96 | break; 97 | 98 | case U8G_COM_MSG_WRITE_SEQ: 99 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 100 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 101 | return u8g_i2c_stop(), 0; 102 | { 103 | register uint8_t *ptr = (uint8_t *)arg_ptr; 104 | while( arg_val > 0 ) 105 | { 106 | if ( u8g_i2c_send_byte(*ptr++) == 0 ) 107 | return u8g_i2c_stop(), 0; 108 | arg_val--; 109 | } 110 | } 111 | // u8g_i2c_stop(); 112 | break; 113 | 114 | case U8G_COM_MSG_WRITE_SEQ_P: 115 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 116 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 117 | return u8g_i2c_stop(), 0; 118 | { 119 | register uint8_t *ptr = (uint8_t *)arg_ptr; 120 | while( arg_val > 0 ) 121 | { 122 | if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 ) 123 | return 0; 124 | ptr++; 125 | arg_val--; 126 | } 127 | } 128 | // u8g_i2c_stop(); 129 | break; 130 | 131 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 132 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 133 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */ 134 | 135 | #ifdef OLD_CODE 136 | if ( i2c_state != 0 ) 137 | { 138 | u8g_i2c_stop(); 139 | i2c_state = 0; 140 | } 141 | 142 | if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 ) 143 | return 0; 144 | 145 | /* setup bus, might be a repeated start */ 146 | /* 147 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 148 | return 0; 149 | if ( arg_val == 0 ) 150 | { 151 | i2c_state = 1; 152 | 153 | if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 ) 154 | return 0; 155 | } 156 | else 157 | { 158 | i2c_state = 2; 159 | if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 ) 160 | return 0; 161 | } 162 | */ 163 | #endif 164 | break; 165 | } 166 | return 1; 167 | } 168 | 169 | #else /* defined(U8G_WITH_PINLIST) */ 170 | 171 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 172 | return 1; 173 | } 174 | 175 | #endif /* defined(U8G_WITH_PINLIST) */ 176 | #endif 177 | -------------------------------------------------------------------------------- /src/m2u8/u8g_cursor.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_cursor.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) 40 | { 41 | u8g->cursor_font = cursor_font; 42 | } 43 | 44 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) 45 | { 46 | u8g->cursor_encoding = encoding; 47 | } 48 | 49 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) 50 | { 51 | u8g->cursor_bg_color = bg; 52 | u8g->cursor_fg_color = fg; 53 | } 54 | 55 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) 56 | { 57 | u8g->cursor_x = cursor_x; 58 | u8g->cursor_y = cursor_y; 59 | } 60 | 61 | void u8g_EnableCursor(u8g_t *u8g) 62 | { 63 | u8g->cursor_fn = u8g_DrawCursor; 64 | } 65 | 66 | void u8g_DisableCursor(u8g_t *u8g) 67 | { 68 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; 69 | } 70 | 71 | void u8g_DrawCursor(u8g_t *u8g) 72 | { 73 | const u8g_pgm_uint8_t *font; 74 | uint8_t color; 75 | uint8_t encoding = u8g->cursor_encoding; 76 | 77 | /* get current values */ 78 | color = u8g_GetColorIndex(u8g); 79 | font = u8g->font; 80 | 81 | /* draw cursor */ 82 | u8g->font = u8g->cursor_font; 83 | encoding++; 84 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 85 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 86 | /* required, because y adjustment should not happen to the cursor fonts */ 87 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 88 | encoding--; 89 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 90 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 91 | /* required, because y adjustment should not happen to the cursor fonts */ 92 | /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */ 93 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 94 | 95 | /* restore previous values */ 96 | u8g->font = font; 97 | u8g_SetColorIndex(u8g, color); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_flipdisc_2x7.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_flipdisc.c 4 | 5 | 1-Bit (BW) Driver for flip disc matrix 6 | 2x 7 pixel height 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #define WIDTH 28 42 | #define HEIGHT 14 43 | #define PAGE_HEIGHT 14 44 | 45 | /* 46 | Write data to the flip disc matrix. 47 | This procedure must be implemented by the user. 48 | Arguments: 49 | id: Id for the matrix. Currently always 0. 50 | page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0 51 | width: The width of the flip disc matrix. Always equal to WIDTH 52 | row1: first data line (7 pixel per byte) 53 | row2: first data line (7 pixel per byte) 54 | */ 55 | void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 56 | 57 | 58 | 59 | void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 60 | 61 | void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)) 62 | { 63 | u8g_write_flip_disc_matrix = cb; 64 | } 65 | 66 | uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 67 | { 68 | switch(msg) 69 | { 70 | case U8G_DEV_MSG_INIT: 71 | break; 72 | case U8G_DEV_MSG_STOP: 73 | break; 74 | case U8G_DEV_MSG_PAGE_NEXT: 75 | { 76 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 77 | 78 | /* current page: pb->p.page */ 79 | /* ptr to the buffer: pb->buf */ 80 | 81 | (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH); 82 | } 83 | break; 84 | case U8G_DEV_MSG_CONTRAST: 85 | return 1; 86 | } 87 | return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg); 88 | } 89 | 90 | uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ; 91 | u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 92 | u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn }; 93 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_gprof.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_gprof.c 4 | 5 | Device for performance measurement with gprof. 6 | Does not write any data, but uses a buffer. 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | 44 | #define WIDTH 128 45 | #define HEIGHT 64 46 | #define PAGE_HEIGHT 8 47 | 48 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 49 | 50 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; 51 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; 52 | 53 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; 54 | 55 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 56 | { 57 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 58 | 59 | switch(msg) 60 | { 61 | case U8G_DEV_MSG_INIT: 62 | break; 63 | case U8G_DEV_MSG_STOP: 64 | break; 65 | case U8G_DEV_MSG_PAGE_FIRST: 66 | u8g_pb_Clear(pb); 67 | u8g_page_First(&(pb->p)); 68 | break; 69 | case U8G_DEV_MSG_PAGE_NEXT: 70 | /* 71 | { 72 | uint8_t i, j; 73 | uint8_t page_height; 74 | page_height = pb->p.page_y1; 75 | page_height -= pb->p.page_y0; 76 | page_height++; 77 | for( j = 0; j < page_height; j++ ) 78 | { 79 | printf("%02d ", j); 80 | for( i = 0; i < WIDTH; i++ ) 81 | { 82 | if ( (u8g_pb_dev_stdout_buf[i] & (1<p)) == 0 ) 92 | { 93 | //printf("\n"); 94 | return 0; 95 | } 96 | u8g_pb_Clear(pb); 97 | break; 98 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 99 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 100 | { 101 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; 102 | u8g_uint_t x2, y2; 103 | 104 | y2 = bbx->y; 105 | y2 += bbx->h; 106 | y2--; 107 | 108 | if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 ) 109 | return 0; 110 | 111 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 112 | x2 = bbx->x; 113 | x2 += bbx->w; 114 | x2--; 115 | 116 | if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 ) 117 | return 0; 118 | } 119 | return 1; 120 | #endif 121 | case U8G_DEV_MSG_GET_PAGE_BOX: 122 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 123 | break; 124 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 125 | break; 126 | case U8G_DEV_MSG_SET_XY_CB: 127 | break; 128 | } 129 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 130 | } 131 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_ks0108_128x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_ks0108_128x64.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | ADDRESS = 0 (Command Mode) 36 | 0x03f Display On 37 | 0x0c0 Start Display at line 0 38 | 0x040 | y write to y address (y:0..63) 39 | 0x0b8 | x write to page [0..7] 40 | 41 | 42 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 43 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 44 | 45 | */ 46 | 47 | #include "u8g.h" 48 | 49 | #define WIDTH 128 50 | #define HEIGHT 64 51 | #define PAGE_HEIGHT 8 52 | 53 | static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = { 54 | U8G_ESC_CS(0), /* disable chip */ 55 | U8G_ESC_ADR(0), /* instruction mode */ 56 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 57 | U8G_ESC_CS(1), /* enable chip 1 */ 58 | 0x03f, /* display on */ 59 | 0x0c0, /* start at line 0 */ 60 | U8G_ESC_DLY(20), /* delay 20 ms */ 61 | U8G_ESC_CS(2), /* enable chip 2 */ 62 | 0x03f, /* display on */ 63 | 0x0c0, /* start at line 0 */ 64 | U8G_ESC_DLY(20), /* delay 20 ms */ 65 | U8G_ESC_CS(0), /* disable all chips */ 66 | U8G_ESC_END /* end of sequence */ 67 | }; 68 | 69 | 70 | uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 71 | { 72 | 73 | switch(msg) 74 | { 75 | case U8G_DEV_MSG_INIT: 76 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 77 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq); 78 | break; 79 | case U8G_DEV_MSG_STOP: 80 | break; 81 | case U8G_DEV_MSG_PAGE_NEXT: 82 | { 83 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 84 | 85 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 86 | u8g_SetChipSelect(u8g, dev, 2); 87 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 88 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 89 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 90 | u8g_WriteSequence(u8g, dev, 64, pb->buf); 91 | u8g_SetChipSelect(u8g, dev, 0); 92 | 93 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 94 | u8g_SetChipSelect(u8g, dev, 1); 95 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 96 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 97 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 98 | u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf); 99 | u8g_SetChipSelect(u8g, dev, 0); 100 | 101 | } 102 | break; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL); 108 | U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL); 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_null.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 40 | { 41 | switch(msg) 42 | { 43 | case U8G_DEV_MSG_SET_8PIXEL: /* most often used command */ 44 | break; 45 | case U8G_DEV_MSG_SET_PIXEL: 46 | break; 47 | case U8G_DEV_MSG_INIT: 48 | break; 49 | case U8G_DEV_MSG_STOP: 50 | break; 51 | case U8G_DEV_MSG_PAGE_FIRST: 52 | break; 53 | case U8G_DEV_MSG_PAGE_NEXT: 54 | break; 55 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 56 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 57 | return 1; 58 | #endif 59 | case U8G_DEV_MSG_GET_PAGE_BOX: 60 | break; 61 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 62 | break; 63 | case U8G_DEV_MSG_SET_XY_CB: 64 | break; 65 | } 66 | return 1; 67 | } 68 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_sbn1661_122x32.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_sbn1661_122x32.c 4 | 5 | WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display) 6 | At the moment only available in the Arduino Environment 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | 42 | #define WIDTH 122 43 | #define HEIGHT 32 44 | #define PAGE_HEIGHT 8 45 | 46 | 47 | static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = { 48 | U8G_ESC_CS(0), /* disable chip */ 49 | U8G_ESC_ADR(0), /* instruction mode */ 50 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds */ 51 | U8G_ESC_CS(1), /* enable chip 1 */ 52 | 0x0af, /* display on */ 53 | 0x0c0, /* display start at line 0 */ 54 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 55 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 56 | U8G_ESC_CS(2), /* enable chip 2 */ 57 | 0x0af, /* display on */ 58 | 0x0c0, /* display start at line 0 */ 59 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 60 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 61 | 62 | U8G_ESC_CS(0), /* disable chip */ 63 | 64 | 65 | U8G_ESC_END /* end of sequence */ 66 | }; 67 | 68 | uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 69 | { 70 | switch(msg) 71 | { 72 | case U8G_DEV_MSG_INIT: 73 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 74 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq); 75 | break; 76 | case U8G_DEV_MSG_STOP: 77 | break; 78 | case U8G_DEV_MSG_PAGE_NEXT: 79 | { 80 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 81 | 82 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 83 | u8g_SetChipSelect(u8g, dev, 1); 84 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 85 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 86 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 87 | u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf); 88 | 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 2); 91 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 92 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 93 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 94 | u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf); 95 | 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | break; 102 | } 103 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 104 | } 105 | 106 | /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */ 107 | U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn); 108 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_tls8204_84x48.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_tls8204_84x48.c 4 | 5 | Display: Nokia 84x48 6 | 7 | Status: Tested with TLS8204V12 Display by Olimex MOD-LCD3310 8 | 9 | Contributed: http://code.google.com/p/u8glib/issues/detail?id=126 10 | 11 | Universal 8bit Graphics Library 12 | 13 | Copyright (c) 2011, olikraus@gmail.com 14 | All rights reserved. 15 | 16 | Redistribution and use in source and binary forms, with or without modification, 17 | are permitted provided that the following conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright notice, this list 20 | of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright notice, this 23 | list of conditions and the following disclaimer in the documentation and/or other 24 | materials provided with the distribution. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 27 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 31 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 33 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 38 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | 40 | 41 | */ 42 | 43 | #include "u8g.h" 44 | 45 | #define WIDTH 84 46 | #define HEIGHT 48 47 | #define PAGE_HEIGHT 8 48 | 49 | 50 | static const uint8_t u8g_dev_tls8204_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(0), /* instruction mode */ 53 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | 0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ 56 | 0x006, /* temp. control: b10 = 2 */ 57 | 0x04 | !!((66-1)&(1u<<6)), 58 | 0x40 | ((66-2) & ((1u<<6)-1)), 59 | 0x013, /* bias system 1:48 */ 60 | 0x0c0, /* medium Vop */ 61 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 62 | 0x00c, /* display on, normal operation */ 63 | U8G_ESC_DLY(100), /* delay 100 ms */ 64 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 65 | 0x00d, /* display on, invert */ 66 | U8G_ESC_DLY(100), /* delay 100 ms */ 67 | U8G_ESC_DLY(100), /* delay 100 ms */ 68 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 69 | 0x00c, /* display on, normal */ 70 | U8G_ESC_DLY(100), /* delay 100 ms */ 71 | U8G_ESC_CS(0), /* disable chip */ 72 | U8G_ESC_END /* end of sequence */ 73 | }; 74 | 75 | 76 | uint8_t u8g_dev_tls8204_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 77 | { 78 | switch(msg) 79 | { 80 | case U8G_DEV_MSG_INIT: 81 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 82 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_tls8204_init_seq); 83 | break; 84 | case U8G_DEV_MSG_STOP: 85 | break; 86 | case U8G_DEV_MSG_PAGE_NEXT: 87 | { 88 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 1); 91 | u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 92 | u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */ 93 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */ 94 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 95 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 96 | return 0; 97 | u8g_SetChipSelect(u8g, dev, 0); 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | /* the contrast adjustment does not work, needs to be analysed */ 102 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 103 | u8g_SetChipSelect(u8g, dev, 1); 104 | u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */ 105 | u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) ); 106 | u8g_WriteByte(u8g, dev, 0x020); /* command mode, extended function set */ 107 | u8g_SetChipSelect(u8g, dev, 0); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | 114 | U8G_PB_DEV(u8g_dev_tls8204_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tls8204_fn, U8G_COM_SW_SPI); 115 | 116 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_uc1611_dogm240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogm240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 64 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(1), // enable chip 47 | U8G_ESC_ADR(0), // instruction mode 48 | 0xF1, // set last COM electrode 49 | 0x3F, // 64-1=63 50 | 0xF2, // set display start line 51 | 0x00, // 0 52 | 0xF3, // set display end line 53 | 0x3F, // 64-1=63 54 | 0x81, // set contrast (0-255) 55 | 0xB7, // 183 56 | 0xC0, // set view 57 | //0x04, // topview 58 | 0x02, // bottomview 59 | 0xA3, // set line rate (9.4k) 60 | 0xE9, // set bias ratio (10) 61 | 0xA9, // enable display 62 | 0xD1, // set black and white mode 63 | U8G_ESC_CS(0), // disable chip 64 | U8G_ESC_END // end of sequence 65 | }; 66 | 67 | static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 68 | { 69 | u8g_WriteByte(u8g, dev, 0x70); 70 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 71 | } 72 | 73 | static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = { 74 | U8G_ESC_ADR(0), /* instruction mode */ 75 | U8G_ESC_CS(1), /* enable chip */ 76 | 0x10, /* set upper 4 bit of the col adr to 0 */ 77 | 0x00, /* set lower 4 bit of the col adr to 0 */ 78 | U8G_ESC_END /* end of sequence */ 79 | }; 80 | 81 | uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 82 | { 83 | switch(msg) 84 | { 85 | case U8G_DEV_MSG_INIT: 86 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq); 88 | break; 89 | case U8G_DEV_MSG_STOP: 90 | break; 91 | case U8G_DEV_MSG_PAGE_NEXT: 92 | { 93 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 94 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start); 95 | setPage(u8g, dev, pb->p.page); /* select current page (uc1611) */ 96 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 97 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 98 | return 0; 99 | u8g_SetChipSelect(u8g, dev, 1); 100 | } 101 | break; 102 | case U8G_DEV_MSG_CONTRAST: 103 | u8g_SetChipSelect(u8g, dev, 0); 104 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 105 | u8g_WriteByte(u8g, dev, 0x81); 106 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */ 107 | u8g_SetChipSelect(u8g, dev, 1); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C); 114 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI); 115 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI); 116 | 117 | -------------------------------------------------------------------------------- /src/m2u8/u8g_dev_uc1611_dogxl240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogxl240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@gmail.com, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 128 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(1), // enable chip 47 | U8G_ESC_ADR(0), // instruction mode 48 | 0xF1, // set last COM electrode 49 | 0x7F, // DOGXL240 50 | 0xF2, // set display start line 51 | 0x00, // 0 52 | 0xF3, // set display end line 53 | 0x7F, // DOGXL240 54 | 0x81, // set contrast (0-255) 55 | 0xAA, // DOGXL240 56 | 0xC0, // set view 57 | //0x04, // topview 58 | 0x02, // bottomview 59 | 0xA3, // set line rate (9.4k) 60 | 0xE9, // set bias ratio (10) 61 | 0xA9, // enable display 62 | 0xD1, // set black and white mode 63 | U8G_ESC_CS(0), // disable chip 64 | U8G_ESC_END // end of sequence 65 | }; 66 | 67 | static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 68 | { 69 | u8g_WriteByte(u8g, dev, 0x70); 70 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 71 | } 72 | 73 | static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = { 74 | U8G_ESC_ADR(0), /* instruction mode */ 75 | U8G_ESC_CS(1), /* enable chip */ 76 | 0x10, /* set upper 4 bit of the col adr to 0 */ 77 | 0x00, /* set lower 4 bit of the col adr to 0 */ 78 | U8G_ESC_END /* end of sequence */ 79 | }; 80 | 81 | static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 82 | { 83 | switch(msg) 84 | { 85 | case U8G_DEV_MSG_INIT: 86 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq); 88 | break; 89 | case U8G_DEV_MSG_STOP: 90 | break; 91 | case U8G_DEV_MSG_PAGE_NEXT: 92 | { 93 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 94 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start); 95 | u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); /* select current page (uc1611) */ 96 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 97 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 98 | return 0; 99 | u8g_SetChipSelect(u8g, dev, 1); 100 | } 101 | break; 102 | case U8G_DEV_MSG_CONTRAST: 103 | u8g_SetChipSelect(u8g, dev, 0); 104 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 105 | u8g_WriteByte(u8g, dev, 0x81); 106 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */ 107 | u8g_SetChipSelect(u8g, dev, 1); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C); 114 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI); 115 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI); 116 | 117 | -------------------------------------------------------------------------------- /src/m2u8/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/src/m2u8/u8g_font_data.c -------------------------------------------------------------------------------- /src/m2u8/u8g_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_line.h 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #include "u8g.h" 37 | 38 | void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2) 39 | { 40 | u8g_uint_t tmp; 41 | u8g_uint_t x,y; 42 | u8g_uint_t dx, dy; 43 | u8g_int_t err; 44 | u8g_int_t ystep; 45 | 46 | uint8_t swapxy = 0; 47 | 48 | /* no BBX intersection check at the moment, should be added... */ 49 | 50 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1; 51 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1; 52 | 53 | if ( dy > dx ) 54 | { 55 | swapxy = 1; 56 | tmp = dx; dx =dy; dy = tmp; 57 | tmp = x1; x1 =y1; y1 = tmp; 58 | tmp = x2; x2 =y2; y2 = tmp; 59 | } 60 | if ( x1 > x2 ) 61 | { 62 | tmp = x1; x1 =x2; x2 = tmp; 63 | tmp = y1; y1 =y2; y2 = tmp; 64 | } 65 | err = dx >> 1; 66 | if ( y2 > y1 ) ystep = 1; else ystep = -1; 67 | y = y1; 68 | for( x = x1; x <= x2; x++ ) 69 | { 70 | if ( swapxy == 0 ) 71 | u8g_DrawPixel(u8g, x, y); 72 | else 73 | u8g_DrawPixel(u8g, y, x); 74 | err -= (uint8_t)dy; 75 | if ( err < 0 ) 76 | { 77 | y += (u8g_uint_t)ystep; 78 | err += (u8g_uint_t)dx; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/m2u8/u8g_page.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_page.c 4 | 5 | page helper functions, only called by the dev handler. 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | /* 42 | setup page count structure 43 | conditions: page_height <= total_height 44 | */ 45 | void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) 46 | { 47 | p->page_height = page_height; 48 | p->total_height = total_height; 49 | p->page = 0; 50 | u8g_page_First(p); 51 | } 52 | 53 | void u8g_page_First(u8g_page_t *p) 54 | { 55 | p->page_y0 = 0; 56 | p->page_y1 = p->page_height; 57 | p->page_y1--; 58 | p->page = 0; 59 | } 60 | 61 | uint8_t u8g_page_Next(u8g_page_t * p) 62 | { 63 | register u8g_uint_t y1; 64 | p->page_y0 += p->page_height; 65 | if ( p->page_y0 >= p->total_height ) 66 | return 0; 67 | p->page++; 68 | y1 = p->page_y1; 69 | y1 += p->page_height; 70 | if ( y1 >= p->total_height ) 71 | { 72 | y1 = p->total_height; 73 | y1--; 74 | } 75 | p->page_y1 = y1; 76 | 77 | return 1; 78 | } 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/m2u8/u8g_pb.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb.c 4 | 5 | common procedures for the page buffer 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | void u8g_pb_Clear(u8g_pb_t *b) 42 | { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | end_ptr += b->width; 46 | do 47 | { 48 | *ptr++ = 0; 49 | } while( ptr != end_ptr ); 50 | } 51 | 52 | /* the following procedure does not work. why? Can be checked with descpic */ 53 | /* 54 | void u8g_pb_Clear(u8g_pb_t *b) 55 | { 56 | uint8_t *ptr = (uint8_t *)b->buf; 57 | uint8_t cnt = b->width; 58 | do 59 | { 60 | *ptr++ = 0; 61 | cnt--; 62 | } while( cnt != 0 ); 63 | } 64 | */ 65 | 66 | /* 67 | intersection assumptions: 68 | a1 <= a2 is always true 69 | */ 70 | /* 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | /* 77 | uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 78 | { 79 | uint8_t c0, c1, c; 80 | c0 = v0 <= b->p.page_y1; 81 | c1 = v1 >= b->p.page_y0; 82 | c = v0 > v1; 83 | if ( c0 && c1 ) return 1; 84 | if ( c0 && c ) return 1; 85 | if ( c1 && c ) return 1; 86 | return 0; 87 | } 88 | */ 89 | 90 | uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1) 91 | { 92 | uint8_t c1, c2, c3, tmp; 93 | c1 = v0 <= pb->p.page_y1; 94 | c2 = v1 >= pb->p.page_y0; 95 | c3 = v0 > v1; 96 | /* 97 | if ( c1 && c2 ) 98 | return 1; 99 | if ( c1 && c3 ) 100 | return 1; 101 | if ( c2 && c3 ) 102 | return 1; 103 | return 0; 104 | */ 105 | 106 | tmp = c1; 107 | c1 &= c2; 108 | c2 &= c3; 109 | c3 &= tmp; 110 | c1 |= c2; 111 | c1 |= c3; 112 | return c1 & 1; 113 | } 114 | 115 | 116 | uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 117 | { 118 | uint8_t /*c0, c1, */ c2, c3; 119 | /* 120 | conditions: b->p.page_y0 < b->p.page_y1 121 | there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed 122 | */ 123 | /* 124 | c0 = v0 < 0; 125 | c1 = v1 < 0; 126 | */ 127 | c2 = v0 > b->width; 128 | c3 = v1 > b->width; 129 | /*if ( c0 && c1 ) return 0;*/ 130 | if ( c2 && c3 ) return 0; 131 | /*if ( c1 && c2 ) return 0;*/ 132 | return 1; 133 | } 134 | 135 | uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx) 136 | { 137 | u8g_uint_t tmp; 138 | 139 | tmp = bbx->y; 140 | tmp += bbx->h; 141 | tmp--; 142 | 143 | if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 ) 144 | return 0; 145 | 146 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 147 | tmp = bbx->x; 148 | tmp += bbx->w; 149 | tmp--; 150 | 151 | return u8g_pb_IsXIntersection(pb, bbx->x, tmp); 152 | } 153 | 154 | void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box) 155 | { 156 | box->x0 = 0; 157 | box->y0 = pb->p.page_y0; 158 | box->x1 = pb->width; 159 | box->x1--; 160 | box->y1 = pb->p.page_y1; 161 | } 162 | 163 | 164 | uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 165 | { 166 | u8g_uint_t v0, v1; 167 | v0 = arg_pixel->y; 168 | v1 = v0; 169 | switch( arg_pixel->dir ) 170 | { 171 | case 0: 172 | break; 173 | case 1: 174 | v1 += 8; /* this is independent from the page height */ 175 | break; 176 | case 2: 177 | break; 178 | case 3: 179 | v0 -= 8; 180 | break; 181 | } 182 | return u8g_pb_IsYIntersection(b, v0, v1); 183 | } 184 | 185 | 186 | 187 | uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev) 188 | { 189 | return u8g_WriteSequence(u8g, dev, b->width, b->buf); 190 | } 191 | 192 | -------------------------------------------------------------------------------- /src/m2u8/u8g_pb16v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb16v2.c 4 | 5 | 16 bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | 44 | void u8g_pb16v2_Clear(u8g_pb_t *b) 45 | { 46 | uint8_t *ptr = (uint8_t *)b->buf; 47 | uint8_t *end_ptr = ptr; 48 | 49 | /* two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte */ 50 | end_ptr += b->width; 51 | end_ptr += b->width; 52 | 53 | do 54 | { 55 | *ptr++ = 0; 56 | } while( ptr != end_ptr ); 57 | } 58 | 59 | void u8g_pb16v2Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 60 | { 61 | b->buf = buf; 62 | b->width = width; 63 | u8g_pb16v2_Clear(b); 64 | } 65 | 66 | void u8g_pb16v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 67 | { 68 | register uint8_t mask; 69 | uint8_t *ptr = b->buf; 70 | y -= b->p.page_y0; 71 | if ( y >= 4 ) 72 | { 73 | ptr += b->width; 74 | } 75 | mask = 0x03; 76 | y &= 0x03; 77 | y <<= 1; 78 | mask <<= y; 79 | mask ^=0xff; 80 | color_index &= 3; 81 | color_index <<= y; 82 | ptr += x; 83 | *ptr &= mask; 84 | *ptr |= color_index; 85 | } 86 | 87 | 88 | void u8g_pb16v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 89 | { 90 | if ( arg_pixel->y < b->p.page_y0 ) 91 | return; 92 | if ( arg_pixel->y > b->p.page_y1 ) 93 | return; 94 | if ( arg_pixel->x >= b->width ) 95 | return; 96 | u8g_pb16v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 97 | } 98 | 99 | 100 | void u8g_pb16v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 101 | { 102 | register uint8_t pixel = arg_pixel->pixel; 103 | do 104 | { 105 | if ( pixel & 128 ) 106 | { 107 | u8g_pb16v2_SetPixel(b, arg_pixel); 108 | } 109 | switch( arg_pixel->dir ) 110 | { 111 | case 0: arg_pixel->x++; break; 112 | case 1: arg_pixel->y++; break; 113 | case 2: arg_pixel->x--; break; 114 | case 3: arg_pixel->y--; break; 115 | } 116 | pixel <<= 1; 117 | } while( pixel != 0 ); 118 | } 119 | 120 | 121 | 122 | uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 123 | { 124 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 125 | switch(msg) 126 | { 127 | case U8G_DEV_MSG_SET_8PIXEL: 128 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 129 | { 130 | u8g_pb16v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 131 | } 132 | break; 133 | case U8G_DEV_MSG_SET_PIXEL: 134 | u8g_pb16v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 135 | break; 136 | case U8G_DEV_MSG_INIT: 137 | break; 138 | case U8G_DEV_MSG_STOP: 139 | break; 140 | case U8G_DEV_MSG_PAGE_FIRST: 141 | u8g_pb16v2_Clear(pb); 142 | u8g_page_First(&(pb->p)); 143 | break; 144 | case U8G_DEV_MSG_PAGE_NEXT: 145 | if ( u8g_page_Next(&(pb->p)) == 0 ) 146 | return 0; 147 | u8g_pb16v2_Clear(pb); 148 | break; 149 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 150 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 151 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 152 | #endif 153 | case U8G_DEV_MSG_GET_PAGE_BOX: 154 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 155 | break; 156 | case U8G_DEV_MSG_GET_WIDTH: 157 | *((u8g_uint_t *)arg) = pb->width; 158 | break; 159 | case U8G_DEV_MSG_GET_HEIGHT: 160 | *((u8g_uint_t *)arg) = pb->p.total_height; 161 | break; 162 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 163 | break; 164 | case U8G_DEV_MSG_SET_XY_CB: 165 | break; 166 | case U8G_DEV_MSG_GET_MODE: 167 | return U8G_MODE_GRAY2BIT; 168 | } 169 | return 1; 170 | } 171 | 172 | 173 | -------------------------------------------------------------------------------- /src/m2u8/u8g_pb8h2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8h2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has horizontal orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 51 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 52 | { 53 | register uint8_t mask; 54 | register uint16_t tmp; 55 | 56 | uint8_t *ptr = b->buf; 57 | 58 | y -= b->p.page_y0; 59 | 60 | tmp = b->width; 61 | tmp >>= 2; 62 | tmp *= (uint8_t)y; 63 | ptr += tmp; 64 | 65 | tmp = x; 66 | tmp >>= 2; 67 | ptr += tmp; 68 | 69 | tmp = x; 70 | tmp &= 3; 71 | tmp <<= 1; 72 | mask = 3; 73 | mask <<= tmp; 74 | mask = ~mask; 75 | color_index &= 3; 76 | color_index <<= tmp; 77 | 78 | *ptr &= mask; 79 | *ptr |= color_index; 80 | } 81 | 82 | 83 | void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 84 | { 85 | if ( arg_pixel->y < b->p.page_y0 ) 86 | return; 87 | if ( arg_pixel->y > b->p.page_y1 ) 88 | return; 89 | if ( arg_pixel->x >= b->width ) 90 | return; 91 | u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 92 | } 93 | 94 | 95 | void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 96 | { 97 | register uint8_t pixel = arg_pixel->pixel; 98 | do 99 | { 100 | if ( pixel & 128 ) 101 | { 102 | u8g_pb8h2_SetPixel(b, arg_pixel); 103 | } 104 | switch( arg_pixel->dir ) 105 | { 106 | case 0: arg_pixel->x++; break; 107 | case 1: arg_pixel->y++; break; 108 | case 2: arg_pixel->x--; break; 109 | case 3: arg_pixel->y--; break; 110 | } 111 | pixel <<= 1; 112 | } while( pixel != 0 ); 113 | } 114 | 115 | 116 | 117 | uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 118 | { 119 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 120 | switch(msg) 121 | { 122 | case U8G_DEV_MSG_SET_8PIXEL: 123 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 124 | { 125 | u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 126 | } 127 | break; 128 | case U8G_DEV_MSG_SET_PIXEL: 129 | u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 130 | break; 131 | case U8G_DEV_MSG_INIT: 132 | break; 133 | case U8G_DEV_MSG_STOP: 134 | break; 135 | case U8G_DEV_MSG_PAGE_FIRST: 136 | u8g_pb_Clear(pb); 137 | u8g_page_First(&(pb->p)); 138 | break; 139 | case U8G_DEV_MSG_PAGE_NEXT: 140 | if ( u8g_page_Next(&(pb->p)) == 0 ) 141 | return 0; 142 | u8g_pb_Clear(pb); 143 | break; 144 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 145 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 146 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 147 | #endif 148 | case U8G_DEV_MSG_GET_PAGE_BOX: 149 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 150 | break; 151 | case U8G_DEV_MSG_GET_WIDTH: 152 | *((u8g_uint_t *)arg) = pb->width; 153 | break; 154 | case U8G_DEV_MSG_GET_HEIGHT: 155 | *((u8g_uint_t *)arg) = pb->p.total_height; 156 | break; 157 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 158 | break; 159 | case U8G_DEV_MSG_SET_XY_CB: 160 | break; 161 | case U8G_DEV_MSG_GET_MODE: 162 | return U8G_MODE_GRAY2BIT; 163 | } 164 | return 1; 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /src/m2u8/u8g_pb8v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8v2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 51 | { 52 | register uint8_t mask; 53 | uint8_t *ptr = b->buf; 54 | y -= b->p.page_y0; 55 | mask = 0x03; 56 | y &= 0x03; 57 | y <<= 1; 58 | mask <<= y; 59 | mask ^=0xff; 60 | color_index &= 3; 61 | color_index <<= y; 62 | ptr += x; 63 | *ptr &= mask; 64 | *ptr |= color_index; 65 | } 66 | 67 | 68 | void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 69 | { 70 | if ( arg_pixel->y < b->p.page_y0 ) 71 | return; 72 | if ( arg_pixel->y > b->p.page_y1 ) 73 | return; 74 | if ( arg_pixel->x >= b->width ) 75 | return; 76 | u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 77 | } 78 | 79 | 80 | void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 81 | { 82 | register uint8_t pixel = arg_pixel->pixel; 83 | do 84 | { 85 | if ( pixel & 128 ) 86 | { 87 | u8g_pb8v2_SetPixel(b, arg_pixel); 88 | } 89 | switch( arg_pixel->dir ) 90 | { 91 | case 0: arg_pixel->x++; break; 92 | case 1: arg_pixel->y++; break; 93 | case 2: arg_pixel->x--; break; 94 | case 3: arg_pixel->y--; break; 95 | } 96 | pixel <<= 1; 97 | } while( pixel != 0 ); 98 | 99 | } 100 | 101 | 102 | 103 | uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 104 | { 105 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 106 | switch(msg) 107 | { 108 | case U8G_DEV_MSG_SET_8PIXEL: 109 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 110 | { 111 | u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 112 | } 113 | break; 114 | case U8G_DEV_MSG_SET_PIXEL: 115 | u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 116 | break; 117 | case U8G_DEV_MSG_INIT: 118 | break; 119 | case U8G_DEV_MSG_STOP: 120 | break; 121 | case U8G_DEV_MSG_PAGE_FIRST: 122 | u8g_pb_Clear(pb); 123 | u8g_page_First(&(pb->p)); 124 | break; 125 | case U8G_DEV_MSG_PAGE_NEXT: 126 | if ( u8g_page_Next(&(pb->p)) == 0 ) 127 | return 0; 128 | u8g_pb_Clear(pb); 129 | break; 130 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 131 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 132 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 133 | #endif 134 | case U8G_DEV_MSG_GET_PAGE_BOX: 135 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 136 | break; 137 | case U8G_DEV_MSG_GET_WIDTH: 138 | *((u8g_uint_t *)arg) = pb->width; 139 | break; 140 | case U8G_DEV_MSG_GET_HEIGHT: 141 | *((u8g_uint_t *)arg) = pb->p.total_height; 142 | break; 143 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 144 | break; 145 | case U8G_DEV_MSG_SET_XY_CB: 146 | break; 147 | case U8G_DEV_MSG_GET_MODE: 148 | return U8G_MODE_GRAY2BIT; 149 | } 150 | return 1; 151 | } 152 | 153 | 154 | -------------------------------------------------------------------------------- /src/m2u8/u8g_state.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_state.c 4 | 5 | backup and restore hardware state 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 38 | device callback: DEV_MSG_INIT 39 | state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G 40 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 41 | 42 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 43 | state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G 44 | DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT 45 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 46 | 47 | */ 48 | 49 | #include 50 | #include "u8g.h" 51 | 52 | void u8g_state_dummy_cb(uint8_t msg) 53 | { 54 | /* the dummy procedure does nothing */ 55 | } 56 | 57 | void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb) 58 | { 59 | u8g->state_cb = backup_cb; 60 | /* in most cases the init message was already sent, so this will backup the */ 61 | /* current u8g state */ 62 | backup_cb(U8G_STATE_MSG_BACKUP_U8G); 63 | } 64 | 65 | 66 | /*===============================================================*/ 67 | /* register variable for restoring interrupt state */ 68 | 69 | #if defined(__AVR__) 70 | uint8_t global_SREG_backup; 71 | #endif 72 | 73 | 74 | 75 | /*===============================================================*/ 76 | /* AVR */ 77 | 78 | #if defined(__AVR__) 79 | #define U8G_ATMEGA_HW_SPI 80 | 81 | /* remove the definition for attiny */ 82 | #if __AVR_ARCH__ == 2 83 | #undef U8G_ATMEGA_HW_SPI 84 | #endif 85 | #if __AVR_ARCH__ == 25 86 | #undef U8G_ATMEGA_HW_SPI 87 | #endif 88 | #endif 89 | 90 | #if defined(U8G_ATMEGA_HW_SPI) 91 | #include 92 | static uint8_t u8g_state_avr_spi_memory[2]; 93 | 94 | void u8g_backup_spi(uint8_t msg) 95 | { 96 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 97 | { 98 | u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR; 99 | } 100 | else 101 | { 102 | uint8_t tmp = SREG; 103 | cli(); 104 | SPCR = 0; 105 | SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)]; 106 | SREG = tmp; 107 | } 108 | } 109 | 110 | #elif defined (U8G_RASPBERRY_PI) 111 | 112 | #include 113 | 114 | void u8g_backup_spi(uint8_t msg) { 115 | printf("u8g_backup_spi %d\r\n",msg); 116 | } 117 | 118 | #elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__ 119 | 120 | #include "sam.h" 121 | 122 | struct sam_backup_struct 123 | { 124 | uint32_t mr; 125 | uint32_t sr; 126 | uint32_t csr[4]; 127 | } sam_backup[2]; 128 | 129 | void u8g_backup_spi(uint8_t msg) 130 | { 131 | uint8_t idx = U8G_STATE_MSG_GET_IDX(msg); 132 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 133 | { 134 | sam_backup[idx].mr = SPI0->SPI_MR; 135 | sam_backup[idx].sr = SPI0->SPI_SR; 136 | sam_backup[idx].csr[0] = SPI0->SPI_CSR[0]; 137 | sam_backup[idx].csr[1] = SPI0->SPI_CSR[1]; 138 | sam_backup[idx].csr[2] = SPI0->SPI_CSR[2]; 139 | sam_backup[idx].csr[3] = SPI0->SPI_CSR[3]; 140 | } 141 | else 142 | { 143 | SPI0->SPI_MR = sam_backup[idx].mr; 144 | SPI0->SPI_CSR[0] = sam_backup[idx].csr[0]; 145 | SPI0->SPI_CSR[1] = sam_backup[idx].csr[1]; 146 | SPI0->SPI_CSR[2] = sam_backup[idx].csr[2]; 147 | SPI0->SPI_CSR[3] = sam_backup[idx].csr[3]; 148 | } 149 | } 150 | 151 | #else 152 | 153 | void u8g_backup_spi(uint8_t msg) 154 | { 155 | } 156 | 157 | #endif 158 | 159 | -------------------------------------------------------------------------------- /src/m2u8/u8g_u16toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u16toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2012, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | const char *u8g_u16toap(char * dest, uint16_t v) 41 | { 42 | uint8_t pos; 43 | uint8_t d; 44 | uint16_t c; 45 | c = 10000; 46 | for( pos = 0; pos < 5; pos++ ) 47 | { 48 | d = '0'; 49 | while( v >= c ) 50 | { 51 | v -= c; 52 | d++; 53 | } 54 | dest[pos] = d; 55 | c /= 10; 56 | } 57 | dest[5] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u16toa(uint16_t v, uint8_t d) 63 | { 64 | static char buf[6]; 65 | d = 5-d; 66 | return u8g_u16toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/m2u8/u8g_u8toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u8toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2011, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 } ; 41 | const char *u8g_u8toap(char * dest, uint8_t v) 42 | { 43 | uint8_t pos; 44 | uint8_t d; 45 | uint8_t c; 46 | for( pos = 0; pos < 3; pos++ ) 47 | { 48 | d = '0'; 49 | c = *(u8g_u8toa_tab+pos); 50 | while( v >= c ) 51 | { 52 | v -= c; 53 | d++; 54 | } 55 | dest[pos] = d; 56 | } 57 | dest[3] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u8toa(uint8_t v, uint8_t d) 63 | { 64 | static char buf[4]; 65 | d = 3-d; 66 | return u8g_u8toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/m2u8/u8g_virtual_screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_virtual_screen.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | struct _u8g_vs_t 40 | { 41 | u8g_uint_t x; 42 | u8g_uint_t y; 43 | u8g_t *u8g; 44 | }; 45 | typedef struct _u8g_vs_t u8g_vs_t; 46 | 47 | #define U8g_VS_MAX 4 48 | uint8_t u8g_vs_cnt = 0; 49 | u8g_vs_t u8g_vs_list[U8g_VS_MAX]; 50 | uint8_t u8g_vs_current; 51 | u8g_uint_t u8g_vs_width; 52 | u8g_uint_t u8g_vs_height; 53 | 54 | uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 55 | { 56 | switch(msg) 57 | { 58 | default: 59 | { 60 | uint8_t i; 61 | for( i = 0; i < u8g_vs_cnt; i++ ) 62 | { 63 | u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); 64 | } 65 | } 66 | return 1; 67 | case U8G_DEV_MSG_PAGE_FIRST: 68 | u8g_vs_current = 0; 69 | if ( u8g_vs_cnt != 0 ) 70 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 71 | return 0; 72 | case U8G_DEV_MSG_PAGE_NEXT: 73 | { 74 | uint8_t ret = 0; 75 | if ( u8g_vs_cnt != 0 ) 76 | ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 77 | if ( ret != 0 ) 78 | return ret; 79 | u8g_vs_current++; /* next device */ 80 | if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */ 81 | return 0; 82 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg); 83 | } 84 | return 0; 85 | case U8G_DEV_MSG_GET_WIDTH: 86 | *((u8g_uint_t *)arg) = u8g_vs_width; 87 | break; 88 | case U8G_DEV_MSG_GET_HEIGHT: 89 | *((u8g_uint_t *)arg) = u8g_vs_height; 90 | break; 91 | case U8G_DEV_MSG_GET_PAGE_BOX: 92 | if ( u8g_vs_current < u8g_vs_cnt ) 93 | { 94 | u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 95 | ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; 96 | ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; 97 | ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; 98 | ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; 99 | } 100 | else 101 | { 102 | ((u8g_box_t *)arg)->x0 = 0; 103 | ((u8g_box_t *)arg)->x1 = 0; 104 | ((u8g_box_t *)arg)->y0 = 0; 105 | ((u8g_box_t *)arg)->y1 = 0; 106 | } 107 | return 1; 108 | case U8G_DEV_MSG_SET_PIXEL: 109 | case U8G_DEV_MSG_SET_8PIXEL: 110 | if ( u8g_vs_current < u8g_vs_cnt ) 111 | { 112 | ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; 113 | ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; 114 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 115 | } 116 | break; 117 | } 118 | return 1; 119 | } 120 | 121 | 122 | 123 | u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; 124 | 125 | void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) 126 | { 127 | if ( vs_u8g->dev != &u8g_dev_vs ) 128 | return; /* abort if there is no a virtual screen device */ 129 | u8g_vs_width = width; 130 | u8g_vs_height = height; 131 | } 132 | 133 | uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) 134 | { 135 | if ( vs_u8g->dev != &u8g_dev_vs ) 136 | return 0; /* abort if there is no a virtual screen device */ 137 | if ( u8g_vs_cnt >= U8g_VS_MAX ) 138 | return 0; /* maximum number of child u8g's reached */ 139 | u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; 140 | u8g_vs_list[u8g_vs_cnt].x = x; 141 | u8g_vs_list[u8g_vs_cnt].y = y; 142 | u8g_vs_cnt++; 143 | return 1; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * main.c 3 | * 4 | * FreeExpression firmware, main program 5 | * 6 | * This source original developed by https://github.com/Arlet/Freecut 7 | * 8 | * This file is part of FreeExpression. 9 | * 10 | * https://github.com/thetazzbot/FreeExpression 11 | * 12 | * FreeExpression is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2. 14 | * 15 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 22 | * 23 | */ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "usb.h" 32 | #include "keypad.h" 33 | #include "timer.h" 34 | #include "stepper.h" 35 | #include "cli.h" 36 | #include "flash.h" 37 | #include "version.h" 38 | #include "dial.h" 39 | #include "hpgl.h" 40 | #include "display.h" 41 | void setup(void); 42 | 43 | 44 | void setup(void) 45 | { 46 | // Watchdogging disabled -- No use while debugging / testing 47 | //wdt_enable( WDTO_30MS ); 48 | keypad_init( ); 49 | display_init(); 50 | usb_init(); 51 | timer_init( ); 52 | stepper_init( ); 53 | flash_init( ); 54 | hpgl_init(); 55 | dial_init( ); 56 | 57 | sei(); // Start interrupts -- Motors will home immediately following this 58 | 59 | msleep(100); 60 | 61 | //display_print(VERSION); 62 | 63 | usb_puts("\f"); 64 | usb_puts(VERSION); 65 | 66 | } 67 | 68 | 69 | int main( void ) 70 | { 71 | setup(); 72 | display_update(); 73 | while( 1 ) 74 | { 75 | cli_poll( ); // polls ready bytes from USB and processes them 76 | wdt_reset( ); 77 | if( flag_25Hz ) 78 | { 79 | flag_25Hz = 0; 80 | 81 | dial_poll( ); // polls the dials and processes their state 82 | keypad_poll( ); // polls the keypad and executes functions 83 | //display_update(); 84 | 85 | } 86 | if( flag_Hz ) 87 | { 88 | flag_Hz = 0; 89 | } 90 | } 91 | //return 0; 92 | } 93 | -------------------------------------------------------------------------------- /src/scale.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Scaling functions used by the HPGL state machine 3 | * 4 | * This file is part of FreeExpression. 5 | * 6 | * https://github.com/thetazzbot/FreeExpression 7 | * 8 | * FreeExpression is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2. 10 | * 11 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 18 | * 19 | */ 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | #include "configs.h" 27 | #include "shvars.h" 28 | #include "scale.h" 29 | 30 | 31 | static double user_xscale, user_yscale, user_translate_x, user_translate_y; 32 | 33 | void translate_init() { 34 | user_xscale = user_yscale = 1; 35 | user_translate_x = user_translate_y = 0; 36 | ip_pad[0] = 0; 37 | ip_pad[1] = 0; 38 | ip_pad[2] = 9500; 39 | ip_pad[3] = 7000; 40 | sc_pad[0] = 0; 41 | sc_pad[1] = 9500; 42 | sc_pad[2] = 0; 43 | sc_pad[3] = 7000; 44 | } 45 | 46 | // use IP and SC data to calculate the scale 47 | void translate_scale() { 48 | int32_t ipxrange = ip_pad[2] - ip_pad[0]; 49 | int32_t ipyrange = ip_pad[3] - ip_pad[1]; 50 | int32_t scxrange = sc_pad[1] - sc_pad[0]; // xmax - xmin 51 | int32_t scyrange = sc_pad[3] - sc_pad[2]; // ymax - ymin 52 | 53 | user_xscale = ((double)ipxrange)/((double)scxrange); 54 | user_yscale = ((double)ipyrange)/((double)scyrange); 55 | //user_xscale = ((double)scxrange)/((double)ipxrange); 56 | //user_yscale = ((double)scyrange)/((double)ipyrange); 57 | user_translate_x = -sc_pad[0]*user_xscale; 58 | user_translate_y = -sc_pad[2]*user_yscale; 59 | 60 | printf_P(PSTR("Scale set to: (%f,%f) translate (%f,%f)"), user_xscale, user_yscale, user_translate_x, user_translate_y); 61 | } 62 | 63 | void userprescale(double absx, double absy, double *ox, double *oy) { 64 | *ox = absx/user_xscale; 65 | *oy = absy/user_yscale; 66 | } 67 | 68 | void userscale(double fx, double fy, int16_t* x, int16_t* y, double* ox, double* oy) { 69 | *x = (int)round(fx*STEPSCALE_X*user_xscale); 70 | *y = (int)round(fy*STEPSCALE_Y*user_yscale); 71 | 72 | *ox = (*x)/(user_xscale*STEPSCALE_X); 73 | *oy = (*y)/(user_yscale*STEPSCALE_Y); 74 | } 75 | 76 | USER_POINT scale_P1P2() { 77 | USER_POINT p; 78 | p.x = ip_pad[2] - ip_pad[0]; 79 | p.y = ip_pad[3] - ip_pad[1]; 80 | 81 | return p; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /src/scale.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCALE_H 2 | #define _SCALE_H 3 | 4 | #include "shvars.h" 5 | 6 | /// Initialize translation and scale. 7 | /// 8 | /// Translation is not implemented. 9 | void translate_init(void); 10 | 11 | /// Use IP and SC data to calculate the scale and translation. 12 | /// 13 | /// Translation is not implemented. 14 | void translate_scale(void); 15 | 16 | /// Transform user coordinates (fx,fy) into plotter coordinates (x,y) according to 17 | /// the transform defined by IP/SC. Then do reverse transform, round and assign 18 | /// resulting values to (ox,oy). 19 | /// @param fx user coordinates x 20 | /// @param fy user coordinates y 21 | /// @param *x (output) absolute stepper x 22 | /// @param *y (output) absolute stepper y 23 | /// @param *ox (output) corrected fx 24 | /// @param *oy (output) corrected fy 25 | /// 26 | /// @see STEPSCALE_X 27 | /// @see STEPSCALE_Y 28 | void userscale(double fx, double fy, int16_t* x, int16_t* y, double* ox, double* oy); 29 | 30 | 31 | /// Something that shouldn't be used 32 | void userprescale(double absx, double absy, double *ox, double *oy); 33 | 34 | /// Something else that should not be used 35 | USER_POINT scale_P1P2(void); 36 | 37 | #endif -------------------------------------------------------------------------------- /src/serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | serial.c - Low level functions for sending and recieving bytes via the serial port 3 | Part of Grbl v0.9 4 | 5 | Copyright (c) 2012-2014 Sungeun K. Jeon 6 | 7 | Grbl is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Grbl is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Grbl. If not, see . 19 | */ 20 | /* 21 | This file is based on work from Grbl v0.8, distributed under the 22 | terms of the MIT-license. See COPYING for more details. 23 | Copyright (c) 2009-2011 Simen Svale Skogsrud 24 | Copyright (c) 2011-2012 Sungeun K. Jeon 25 | */ 26 | 27 | #ifndef serial_h 28 | #define serial_h 29 | 30 | #define BAUD_RATE 9600 31 | 32 | #define ENABLE_XONXOFF 33 | 34 | #define UART1_RECEIVE_INTERRUPT USART1_RX_vect 35 | #define UART1_TRANSMIT_INTERRUPT USART1_UDRE_vect 36 | #define UART1_STATUS UCSR1A 37 | #define UART1_CONTROL UCSR1B 38 | #define UART1_DATA UDR1 39 | #define UART1_UDRIE UDRIE1 40 | 41 | #ifndef RX_BUFFER_SIZE 42 | #define RX_BUFFER_SIZE 128 43 | #endif 44 | #ifndef TX_BUFFER_SIZE 45 | #define TX_BUFFER_SIZE 64 46 | #endif 47 | 48 | #define SERIAL_NO_DATA 0xff 49 | 50 | #ifdef ENABLE_XONXOFF 51 | #define RX_BUFFER_FULL 96 // XOFF high watermark 52 | #define RX_BUFFER_LOW 32 // XON low watermark 53 | #define SEND_XOFF 1 54 | #define SEND_XON 2 55 | #define XOFF_SENT 3 56 | #define XON_SENT 4 57 | #define XOFF_CHAR 0x13 58 | #define XON_CHAR 0x11 59 | #endif 60 | 61 | void serial_init(void); 62 | 63 | // Writes one byte to the TX serial buffer. Called by main program. 64 | void serial_write(uint8_t data); 65 | 66 | // Fetches the first byte in the serial read buffer. Called by main program. 67 | uint8_t serial_read(void); 68 | 69 | // Reset and empty data in read buffer. Used by e-stop and reset. 70 | void serial_reset_read_buffer(void); 71 | 72 | // Returns the number of bytes used in the RX serial buffer. 73 | uint8_t serial_get_rx_buffer_count(void); 74 | 75 | // Returns the number of bytes used in the TX serial buffer. 76 | // NOTE: Not used except for debugging and ensuring no TX bottlenecks. 77 | uint8_t serial_get_tx_buffer_count(void); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/shvars.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "shvars.h" 4 | 5 | 6 | 7 | 8 | char scratchpad[SCRATCHPAD_SIZE]; 9 | double numpad[4]; 10 | int32_t ip_pad[4]; 11 | int32_t sc_pad[4]; 12 | 13 | STEPPER_POINT stepper_loc; 14 | 15 | USER_POINT user_loc; 16 | 17 | uint8_t borderflags; ///< Margin flags: MSB [0 0 ZINF ZSUP YINF YSUP XINF XSUP] LSB 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/shvars.h: -------------------------------------------------------------------------------- 1 | #ifndef _SHVARS_H 2 | #define _SHVARS_H 3 | 4 | #define SCRATCHPAD_SIZE 64 5 | 6 | ///< Absolute coordinates used for stepper motion. 7 | ///< Negative means invalid. 8 | typedef int16_t STEPPER_COORD; 9 | 10 | ///< User coordinates used in input, arc calculation etc. 11 | typedef double USER_COORD; 12 | 13 | 14 | typedef struct _stepper_xy { 15 | STEPPER_COORD x; 16 | STEPPER_COORD y; 17 | } STEPPER_POINT; 18 | 19 | typedef struct _user_xy { 20 | USER_COORD x; 21 | USER_COORD y; 22 | } USER_POINT; 23 | 24 | /// Acceleration modes. 25 | /// See configs.h for marginal values. 26 | typedef enum _acceleration_modes { 27 | ACCEL_FIXSLOW = 0, ///< Move slowly, fixed speed 28 | ACCEL_FIXFAST, ///< Move fast, fastest possible speed 29 | ACCEL_FIXMEDIUM, ///< Fixed average speed 30 | ACCEL_ACCEL, ///< Ramp speed up 31 | ACCEL_DECEL, ///< Ramp speed down 32 | } ACCEL_MODE; 33 | 34 | extern char scratchpad[]; ///< character scratchpad used by scanner 35 | extern double numpad[]; ///< stored parameters of AA and similar commands 36 | extern int32_t ip_pad[]; ///< stored parameters of IP command (4) 37 | extern int32_t sc_pad[]; ///< stored parameters of SC command (4) 38 | 39 | extern STEPPER_POINT stepper_loc; ///< absolute stepper coordinates 40 | 41 | extern USER_POINT user_loc; ///< rounded location in user coordinate system (used for arc calculation) 42 | 43 | extern uint8_t borderflags; ///< Margin flags: MSB [0 0 ZINF ZSUP YINF YSUP XINF XSUP] LSB 44 | 45 | #endif -------------------------------------------------------------------------------- /src/spi.c: -------------------------------------------------------------------------------- 1 | /*! \file spi.c \brief SPI interface driver. */ 2 | //***************************************************************************** 3 | // 4 | // File Name : 'spi.c' 5 | // Title : SPI interface driver 6 | // Author : Pascal Stang - Copyright (C) 2000-2002 7 | // Created : 11/22/2000 8 | // Revised : 06/06/2002 9 | // Version : 0.6 10 | // Target MCU : Atmel AVR series 11 | // Editor Tabs : 4 12 | // 13 | // NOTE: This code is currently below version 1.0, and therefore is considered 14 | // to be lacking in some functionality or documentation, or may not be fully 15 | // tested. Nonetheless, you can expect most functions to work. 16 | // 17 | // This code is distributed under the GNU Public License 18 | // which can be found at http://www.gnu.org/licenses/gpl.txt 19 | // 20 | //***************************************************************************** 21 | 22 | #include 23 | #include 24 | 25 | #include "spi.h" 26 | 27 | // Define the SPI_USEINT key if you want SPI bus operation to be 28 | // interrupt-driven. The primary reason for not using SPI in 29 | // interrupt-driven mode is if the SPI send/transfer commands 30 | // will be used from within some other interrupt service routine 31 | // or if interrupts might be globally turned off due to of other 32 | // aspects of your program 33 | // 34 | // Comment-out or uncomment this line as necessary 35 | //#define SPI_USEINT 36 | 37 | #ifdef SPI_USEINT 38 | // variables 39 | static volatile u08 spiTransferComplete; 40 | 41 | // SPI interrupt service handler 42 | SIGNAL(SIG_SPI) 43 | { 44 | spiTransferComplete = TRUE; 45 | } 46 | #endif 47 | 48 | // access routines 49 | void spiInit() 50 | { 51 | #ifdef __AVR_ATmega1281__ 52 | // setup SPI I/O pins 53 | sbi(PORTB, 1); // set SCK hi 54 | sbi(DDRB, 1); // set SCK as output 55 | cbi(DDRB, 3); // set MISO as input 56 | sbi(DDRB, 2); // set MOSI as output 57 | sbi(DDRB, 0); // SS must be output for Master mode to work 58 | #elif __AVR_ATmega8__ 59 | // setup SPI I/O pins 60 | sbi(PORTB, 5); // set SCK hi 61 | sbi(DDRB, 5); // set SCK as output 62 | cbi(DDRB, 4); // set MISO as input 63 | sbi(DDRB, 3); // set MOSI as output 64 | sbi(DDRB, 2); // SS must be output for Master mode to work 65 | #else 66 | #pragma message( "No Matching device define for SPI configuration") 67 | #endif 68 | 69 | // setup SPI interface : 70 | // master mode 71 | sbi(SPCR, MSTR); 72 | // clock = f/4 73 | // cbi(SPCR, SPR0); 74 | // cbi(SPCR, SPR1); 75 | // clock = f/16 76 | sbi(SPCR, SPR0); 77 | cbi(SPCR, SPR1); 78 | //Select Mode 3 79 | sbi(SPCR, CPHA); 80 | sbi(SPCR, CPOL); 81 | // Data order LSB first 82 | sbi(SPCR,DORD); 83 | // enable SPI 84 | sbi(SPCR, SPE); 85 | 86 | // clear status 87 | inb(SPSR); 88 | 89 | 90 | // enable SPI interrupt 91 | #ifdef SPI_USEINT 92 | spiTransferComplete = TRUE; 93 | sbi(SPCR, SPIE); 94 | #endif 95 | } 96 | /* 97 | void spiSetBitrate(u08 spr) 98 | { 99 | outb(SPCR, (inb(SPCR) & ((1<>8) & 0x00FF))<<8; 142 | // send LS byte of given data 143 | rxData |= (spiTransferByte(data & 0x00FF)); 144 | 145 | // return the received data 146 | return rxData; 147 | } 148 | -------------------------------------------------------------------------------- /src/spi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thetazzbot/FreeExpression/6f0efa9c4b8906e9f980a792bf9b80823b74bb03/src/spi.h -------------------------------------------------------------------------------- /src/stepper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * stepper.h 3 | * 4 | * stepper X/Y/Z movement 5 | * 6 | This source original developped by https://github.com/Arlet/Freecut 7 | * 8 | * This file is part of FreeExpression. 9 | * 10 | * https://github.com/thetazzbot/FreeExpression 11 | * 12 | * FreeExpression is free software: you can redistribute it and/or modify it 13 | * under the terms of the GNU General Public License version 2. 14 | * 15 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 16 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 17 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 18 | * License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 22 | * 23 | */ 24 | 25 | #ifndef STEPPER_H 26 | #define STEPPER_H 27 | 28 | void stepper_init( void ); 29 | void stepper_tick( void ); 30 | void stepper_move( int x, int y ); 31 | void stepper_draw( int x, int y ); 32 | void stepper_speed( int delay ); 33 | void stepper_pressure( int pressure ); 34 | void stepper_home( void ); 35 | void stepper_set_origin00(void ); 36 | void stepper_unload_paper( void ); 37 | void stepper_load_paper( void ); 38 | void pen_up(void); 39 | void pen_down(void); 40 | void stepper_jog_manual(int direction, int dist); 41 | void stepper_off( void ); 42 | enum state do_next_command( void ); 43 | 44 | // These values are opposite of their named meaning 45 | // 1023 is "no pressure applied" and represents a very long 46 | // delay on the PWM of the pen's MOSFET port 47 | // 25 translates to "maximum voltage/current allowed" and 48 | // pushes close to 12 volts through the MOSFET to the pen's solenoid 49 | #define MAX_PEN_PWM 500 // MAX PWM for stepper solenoid i.e. nearly no pressure ~ 10Gram 50 | #define MIN_PEN_PWM 100 // MIN PWM for stepper solenoid i.e max pressure it can do ~ 300gram when cold, 275 gram when hot. 51 | #define MAX_CUTTER_P_RANGES 10 // The number of pressure choices 52 | #define MAX_STEPPER_SPEED_RANGES 9 // the number of speed choices 53 | #endif 54 | -------------------------------------------------------------------------------- /src/timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * timer.h 3 | * 4 | * 5 | * This file is part of FreeExpression. 6 | * 7 | * https://github.com/thetazzbot/FreeExpression 8 | * 9 | * FreeExpression is free software: you can redistribute it and/or modify it 10 | * under the terms of the GNU General Public License version 2. 11 | * 12 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 15 | * License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 19 | * 20 | */ 21 | #ifndef TIMER_H 22 | #define TIMER_H 23 | 24 | void timer_init( void ); 25 | void usleep( int usecs ); 26 | void msleep( unsigned msecs ); 27 | void beeper_on( int Hz ); 28 | void beeper_off( void ); 29 | void timer_set_stepper_speed( int delay ); 30 | void timer_set_pen_pressure( int pressure ); 31 | int timer_get_pen_pressure(void); 32 | int timer_get_stepper_speed(void); 33 | void beep(void); 34 | extern volatile uint8_t flag_Hz; 35 | extern volatile uint8_t flag_25Hz; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/usb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * usb.c 3 | * 4 | * The USB port is a UART, connected to a FTDI chip. 5 | * This file is a wrapper on top of the low level serial routines found in serial.c 6 | * 7 | * This file is part of FreeExpression. 8 | * 9 | * https://github.com/thetazzbot/FreeExpression 10 | * 11 | * FreeExpression is free software: you can redistribute it and/or modify it 12 | * under the terms of the GNU General Public License version 2. 13 | * 14 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 17 | * License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "usb.h" 30 | #include "serial.h" 31 | 32 | 33 | void usb_puts(const char *s ) 34 | { 35 | while (*s != '\0') { 36 | serial_write(*s++); 37 | } 38 | } 39 | 40 | void usb_putc(uint8_t c) 41 | { 42 | serial_write(c); 43 | } 44 | 45 | uint8_t usb_getc() 46 | { 47 | return serial_read(); 48 | } 49 | 50 | int usb_haschar(void) 51 | { 52 | return serial_get_rx_buffer_count()>0; 53 | } 54 | 55 | 56 | /* 57 | * initialize USB UART. Assume fixed baudrate of 115200, and default 8N1. 58 | */ 59 | void usb_init( void ) 60 | { 61 | serial_init(); 62 | } 63 | -------------------------------------------------------------------------------- /src/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * usb.h 3 | * 4 | * This file is part of FreeExpression. 5 | * 6 | * https://github.com/thetazzbot/FreeExpression 7 | * 8 | * FreeExpression is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2. 10 | * 11 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 18 | * 19 | */ 20 | #ifndef USB_H 21 | #define USB_H 22 | 23 | #include 24 | #include "serial.h" 25 | void usb_init( void ); 26 | int usb_haschar(void); 27 | void usb_putc( uint8_t c); 28 | uint8_t usb_getc(void); 29 | void usb_puts(const char *s ); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /src/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * version.h 3 | * 4 | * This file is part of FreeExpression. 5 | * 6 | * https://github.com/thetazzbot/FreeExpression 7 | * 8 | * FreeExpression is free software: you can redistribute it and/or modify it 9 | * under the terms of the GNU General Public License version 2. 10 | * 11 | * FreeExpression is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 13 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 14 | * License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with FreeExpression. If not, see http://www.gnu.org/licenses/. 18 | * 19 | */ 20 | #define VERSION "FreeExpression v0.3g" 21 | 22 | --------------------------------------------------------------------------------